localnulltest: Local variable selection

View source: R/localnulltest.R

localnulltestR Documentation

Local variable selection

Description

Learn whether covariate effects are zero at given coordinates using Bayesian model selection or information criteria.

Use coef to extract estimates and posterior probabilities for local effects.

Usage


localnulltest(y, x, z, x.adjust, localgridsize=100, localgrid,
nbaseknots=20, nlocalknots=c(5,10,15), basedegree=3, cutdegree=0,
usecutbasis=TRUE, priorCoef=normalidprior(taustd=1),
priorGroup=normalidprior(taustd=1), priorDelta=modelbbprior(),
mc.cores=min(4,length(nlocalknots)), return.mcmc=FALSE, verbose=FALSE,
...)

localnulltest_fda(y, x, z, x.adjust, function_id,
Sigma='AR/MA', localgridsize=100, localgrid, nbaseknots=20,
nlocalknots=c(5,10,15), basedegree=3, cutdegree=0, usecutbasis=TRUE,
priorCoef=momprior(), priorGroup=groupmomprior(),
priorDelta=modelbbprior(), mc.cores=min(4,length(nlocalknots)),
return.mcmc=FALSE, verbose=FALSE, ...)

localnulltest_givenknots(y, x, z, x.adjust, localgridsize=100,
localgrid, nbaseknots=20, nlocalknots=10, basedegree=3, cutdegree=0,
usecutbasis=TRUE, priorCoef=normalidprior(taustd=1),
priorGroup=normalidprior(taustd=1), priorDelta=modelbbprior(),
verbose=FALSE, ...)

localnulltest_fda_givenknots(y, x, z, x.adjust, function_id,
Sigma='AR/MA', localgridsize=100, localgrid, nbaseknots=20,
nlocalknots=10, basedegree=3, cutdegree=0, usecutbasis=TRUE,
priorCoef=normalidprior(taustd=1), priorGroup=normalidprior(taustd=1),
priorDelta=modelbbprior(), verbose=FALSE, ...)

Arguments

y

Vector with the outcome variable

x

Numerical matrix with covariate values

z

Matrix with d-dimensional coordinates (d>=1$ for each entry in y, and d columns)

x.adjust

Optionally, further adjustment covariates to be included in the model with no testing being performed

function_id

Function identifier. It is assumed that one observes multiple functions over z, this is the identifier of each individual function

Sigma

Error covariance. By default 'identity', other options are 'MA', 'AR' or 'AR/MA' (meaning that BIC is used to choose between MA and AR). Alternatively the user can supply a function such that Sigma(z[i,],z[j,]) returns the within-function cov(y[i,], y[j,])

localgridsize

Local test probabilities will be returned for a grid of z values of size localgridsize for each dimension

localgrid

Regions at which tests will be performed. Defaults to dividing each [min(z[,i]), max(z[,i])] into 10 equal intervals. If provided, localgrid must be a list with one entry for each z[,i], containing a vector with the desired grid for that z[,i]

nbaseknots

Number of knots for the spline approximation to the baseline effect of x on y

nlocalknots

Number of knots for the basis capturing the local effects

basedegree

Degree of the spline approximation to the baseline

cutdegree

Degree of the cut spline basis used for testing

usecutbasis

If FALSE, then the basis is not cut and a standard spline basis is returned (not recommended unless you know what you're doing)

priorCoef

Prior on the coefficients, passed on to modelSelection

priorGroup

Prior on grouped coefficients, passed on to modelSelection

priorDelta

Prior on the models, passed on to modelSelection

mc.cores

If package parallel is available on your system and nlocalknots has several entries defining several resolution levels, they will be run in parallel on mc.cores

return.mcmc

Set to TRUE to return the MCMC output from modelSelection

verbose

If TRUE some progress information is printed

...

Other arguments to be passed on to modelSelection, e.g. family='binomial' for logistic regression

Details

Local variable selection considers the model

y_i= \beta_0(z_i) + sum_{j=1}^p \beta_j(z_i, x_i) + e_i

\beta_0(z_i) is the baseline mean

\beta_j(z_i,x_i) is local effect of covariate j at coordinate z_i

e_i a Gaussian error term assumed either independent or with a covariance structure given by Sigma. If assuming independence it is possible to consider alternatives to Gaussianity, e.g. set family='binomial' for logistic regression or family='poisson' for Poisson regression

Note: a sum-to-zero type constraint is set on \beta_1(z_i,x_i) so that it defines a deviation from the baseline mean \beta_0(z_i)

We model \beta_0 using B-splines of degree basedegree with nbaseknots knots. We model \beta_j using B-splines of degree cutdegree with nlocalknots. Using cutdegree=0 runs fastest is usually gives similar inference than higher degrees, and is hence recommended by default.

Value

Object of class localtest, which extends a list with elements

covareffects

Estimated local covariate effects at different z values, 0.95 posterior intervals and posterior probability for the existence of an effect

pplocalgrid

Posterior probabilities for the existence of an effect for regions of z values. Do not use these unless you know what you're doing

covareffects.mcmc

MCMC output used to build covareffects. Only returned if return.mcmc=TRUE

ms

Objects of class msfit returned by modelSelection

pp_localknots

Posterior probability for each resolution level (value of nlocalknots)

Sigma

Input parameter

nlocalknots

Input parameter

basedegree

Input parameter

cutdegree

Input parameter

knots

Input parameters

regionbounds

List with region bounds defined by the local testing knots at each resolution level

Author(s)

David Rossell

Examples


#Simulate outcome and 2 covariates
#Covariate 1 has local effect for z>0
#Covariate 2 has no effect for any z

truemean= function(x,z) {
    ans= double(nrow(x))
    group1= (x[,1]==1)
    ans[group1]= ifelse(z[group1] <=0, cos(z[group1]), 1)
    ans[!group1]= ifelse(z[!group1]<=0, cos(z[!group1]), 1/(z[!group1]+1)^2)
    return(ans)
}

n= 1000
x1= rep(0:1,c(n/2,n/2))
x2= x1 + rnorm(n)
x= cbind(x1,x2)
z= runif(n,-3,3)
m= truemean(x,z)
y= truemean(x,z) + rnorm(n, 0, .5)

#Run localnulltest with 10 knots
fit0= localnulltest(y, x=x, z=z, nlocalknots=10, niter=1000)

#Estimated covariate effects and posterior probabilities
b= coef(fit0)
b


mombf documentation built on May 29, 2024, 11:01 a.m.