predict.mr.ash: Predict Outcomes or Extract Coefficients from Mr.ASH Fit

View source: R/misc.R

predict.mr.ashR Documentation

Predict Outcomes or Extract Coefficients from Mr.ASH Fit

Description

This function predicts outcomes (y) given the observed variables (X) and a Mr.ASH model; alternatively, retrieve the estimates of the regression coefficients.

Usage

## S3 method for class 'mr.ash'
predict(object, newx = NULL, type = c("response", "coefficients"), ...)

Arguments

object

A mr_ash fit, usually the result of calling mr.ash.

newx

The input matrix, of dimension (n,p); each column is a single predictor; and each row is an observation vector. Here, n is the number of samples and p is the number of predictors. When newx is NULL, the fitted values for the training data are provided.

type

The type of output. For type = "response", predicted or fitted outcomes are returned; for type = "coefficients", the estimated coefficients are returned.

...

Additional arguments passed to the default S3 method.

Value

For type = "response", predicted or fitted outcomes are returned; for type = "coefficients", the estimated coefficients are returned.

Examples

## generate synthetic data
set.seed(1)
n           = 200
p           = 300
X           = matrix(rnorm(n*p),n,p)
beta        = double(p)
beta[1:10]  = 1:10
y           = X %*% beta + rnorm(n)

## fit mr.ash
fit.mr.ash  = mr.ash(X, y)

## predict
Xnew        = matrix(rnorm(n*p),n,p)
ypred       = predict(fit.mr.ash, Xnew)


stephenslab/mr.ash.alpha documentation built on Oct. 31, 2023, 4:21 p.m.