Skip to content
cranPublic

About

❗ This is a read-only mirror of the CRAN R package repository. kir — Knowledge Integration Regression for Mean and Quantile Models. Homepage: https://arxiv.org/abs/2406.12212v3

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kir: Knowledge Integration Regression for Mean and Quantile Models

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.

Installation

Install the released version from CRAN:

install.packages("kir")

Quick start

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").

Which prior input should I use?

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").

How to read the output

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
  • zeta is the selected knowledge weight. zeta: 0 means the prior received no weight and the fit uses your data only; values near 1 mean the fit follows the prior closely.
  • lambda is the penalty strength; larger values set more coefficients to zero.
  • CV prediction loss is the average error on held-out folds: squared error for kir(), check loss (the quantile-regression loss) for kiqr(). The CV loss of the best fit without the prior is stored in summary(fit)$tuning$value_no_prior.
  • one-standard-error rule (1se): among the fits at the selected zeta, the sparsest one whose CV loss is within one standard error of the minimum. Use rule = "min" in coef(), predict() or summary() for the minimum-loss fit.
  • * marks the predictors you supplied as prior variables.
  • Solver: should say converged. print(summary(fit), details = TRUE) shows the full diagnostics, which are also stored in fit$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.

Running time and grids

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 of lambda values for every zeta and 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, so cores > 1 pays off for longer fits. Results do not depend on cores or on the platform;
  • use a coarser zeta grid, 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.

More information

  • ?kir and ?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_data and ?simulate_snp_data: simulated data, including the genotype design of the paper.
  • NEWS.md: changes between versions.

About

❗ This is a read-only mirror of the CRAN R package repository. kir — Knowledge Integration Regression for Mean and Quantile Models. Homepage: https://arxiv.org/abs/2406.12212v3

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages