Learn R Programming

gtx (version 0.0.8)

stepdown.moments2: Stepwise downward model selection using summary statistic matrix.

Description

Terms are dropped iteratively from a regression model until the reduction of improvement in fit (judged by the P-value for a partial t-test or score test) is signicant at a specified threshold. The method implemented here makes use of a pre-built sufficient summary statistic matrix, which contains the (weighted) second moments between all the variables that are being assessed for inclusion in the regression model. The calculations are exact for a normal linear model and correspond to a score test for a generalised linear model.

Usage

stepdown.moments2(xtwx, leftvar, biggest, smallest, p.thresh = 0.05, n = NULL, vscale = NULL)

Arguments

xtwx
a matrix of (weighted) second moments, typically built using make.moments2.
leftvar
name of the response variable (the left hand side of the formula).
biggest
name(s) of the explanatory variables in the biggest model to fit, i.e.\ variables to consider for inclusion.
smallest
name(s) of the explanatory variables in the smallest model to fit, i.e.\ variables that must be included.
p.thresh
P-value threshold for proceeding to add a term to the model.
n
sample size, only needed for the normal linear model if there is not a single intercept “ONE” for all individuals.
vscale
parameter, set to NULL for normal linear model and 1 for logistic regression.

Value

The fitted model, as returned by calling lm.moments2 or est.moments2. This is a list with slots for the effect size estimates, standard errors, and a precision matrix.

Details

This performs stepwise downward model selection. Significance of terms considered for inclusion is determined using identical calculations to lm.moments2 and est.moments2.

When the vscale argument is NULL this function assumes that the xtwx argument was calculated with unit weights and therefore that a linear model fit is required with error variance estimated from the data.

When the vscale argument is set equal to 1 this function assumes that the xtwx argument was calculated with weights calculated such that a correct likelihood function can be recovered and therefore that a generalised linear model fit is required.

Values other than NULL or 1 for the vscale parameter may not be what you think. Do not use other values unless you are absolutely sure that you understand what are doing. See the manuscript for details.

Examples

Run this code
data(mthfrex)
xtx <- make.moments2(mthfr.params, c("SBP", "DBP", "SexC", "Age"), mthfrex)
allsnps <- paste(mthfr.params$snp, mthfr.params$coded.allele, sep = "_")
myfit <- stepdown.moments2(xtx, "SBP", allsnps, c("ONE", "SexC", "Age"))
## much faster than stepAIC but only steps to bigger models
cbind(beta = myfit$betahat, se = myfit$se, t = myfit$beta/myfit$se)

Run the code above in your browser using DataLab