kir fits sparse regression models that borrow information from earlier
studies. kir() models the mean of the outcome and kiqr() models a
quantile of it (for example the median or the 90th percentile). Both
combine your data with prior knowledge: a list of important predictors,
effect sizes from an earlier study, or predictions from another model. A
knowledge weight zeta between 0 and 1 says how much the fit trusts the
prior. It is chosen from your data, so if the prior does not help, the fit
falls back to your data alone (zeta = 0).
The quantile method (KIQR) is described in Wang, Lian, Yu, Zu and Zhang (2026), arXiv:2406.12212. The mean method implements the prior LASSO of Jiang, He and Zhang (2016) and a prior SCAD counterpart.
Install the released version from CRAN:
install.packages("kir")library(kir)
sim <- simulate_sparse_data(n = 100, p = 30, seed = 1)
fit0 <- kir(sim$x, sim$y, seed = 1) # no prior
fit1 <- kir(sim$x, sim$y, prior_vars = sim$active, seed = 1) # important predictors
summary(fit1)
# Quantile regression: under a minute with the default grids on one core;
# see "Running time and grids" to make it faster.
qfit <- kiqr(sim$x, sim$y, prior_vars = sim$active, tau = 0.5, seed = 1)
summary(qfit)seed makes the cross-validation (CV) folds reproducible and leaves your
own random-number stream unchanged. coef() and predict() work as for
other models; predict(fit) without newdata returns the fitted values.
For a longer walk-through, see vignette("kir").
Supply at most one of these:
| What you have | Argument | How to prepare it |
|---|---|---|
| A list of important predictors | prior_vars |
Column names or positions in x. The package fits a penalized model in which these predictors are not penalized (the Prior fit) and uses its predictions as the prior. |
| Effect sizes from an earlier study | beta_prior |
One slope per column of x, in the same order, units and coding as x; use 0 where there is no prior effect. Named values are matched to colnames(x). The intercept is computed from your data. For kiqr(), the slopes must be for the same quantile tau. |
| Predictions for your subjects from another model | y_prior |
One value per row of x, from a model that was not fitted to your y. If the prior was built from your own data, use prior_vars instead. |
Without any of them, zeta is fixed at 0 and the fit is ordinary penalized
regression (SCAD by default, or penalty = "LASSO").
Summary of Knowledge Integration Regression fit
Penalty: SCAD
Selection: cross-validation, 5 folds, one-standard-error rule (1se)
Observations: 100 Predictors: 30
lambda: 0.299876 zeta: 0.1
CV prediction loss (lower is better): 1.782 (SE 0.278)
Solver: kir SCAD coordinate descent, converged
Selected predictors: 10 of 30, 10 marked * as prior variables
zetais the selected knowledge weight.zeta: 0means the prior received no weight and the fit uses your data only; values near 1 mean the fit follows the prior closely.lambdais the penalty strength; larger values set more coefficients to zero.CV prediction lossis the average error on held-out folds: squared error forkir(), check loss (the quantile-regression loss) forkiqr(). The CV loss of the best fit without the prior is stored insummary(fit)$tuning$value_no_prior.one-standard-error rule (1se): among the fits at the selectedzeta, the sparsest one whose CV loss is within one standard error of the minimum. Userule = "min"incoef(),predict()orsummary()for the minimum-loss fit.*marks the predictors you supplied as prior variables.Solver:should sayconverged.print(summary(fit), details = TRUE)shows the full diagnostics, which are also stored infit$convergence.
kiqr() may warn once that quantreg found possibly non-unique solutions
in some of its quantile-regression fits. Quantile regression often has
several equally good solutions; the warning does not mean the final fit
failed. Check the Solver: line instead.
?`kir-package` has a glossary of the terms used in the output.
By default both functions choose lambda and zeta by 5-fold CV over 11
values of zeta and an automatic lambda path (30 values for kiqr(), 100
for kir()).
kir()is fast: a few seconds or less for hundreds of predictors.kiqr()with a prior is slower, because it fits a path oflambdavalues for everyzetaand fold. The quick-start example (100 observations, 30 predictors) takes about 40 seconds on one core and about 12 seconds on four. In one test with 200 observations and 500 predictors on 8 cores, the default CV took about 6 minutes and HBIC about 3 minutes.
To shorten kiqr():
- use
cores, e.g.cores = 4. On Windows the workers are separate R sessions, which take a few seconds to start, socores > 1pays off for longer fits. Results do not depend oncoresor on the platform; - use a coarser
zetagrid, e.g.zeta = c(0, 0.25, 0.5, 0.75, 1); - use
method = "hbic", which fits each candidate once instead of once per fold (HBIC needs at least three predictors).
Examples in the help pages use small grids and settings such as
huber_gamma = 0.1 or max_iter = 3000 only to run quickly. For a real
analysis, leave these arguments out to use the defaults.
?kirand?kiqr: all arguments, the models and the prior inputs.?kiqr_fit,?kiqr_cv,?kiqr_hbic,?kir_fit,?kir_cv,?kir_hbic: the fitting engines, the solvers, the automatic grids and convergence diagnostics.?simulate_sparse_dataand?simulate_snp_data: simulated data, including the genotype design of the paper.NEWS.md: changes between versions.