View source: R/localnulltest.R
localnulltest | R Documentation |
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.
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, ...)
y |
Vector with the outcome variable |
x |
Numerical matrix with covariate values |
z |
Matrix with d-dimensional coordinates (d>=1$ for each entry in |
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
|
localgridsize |
Local test probabilities will be returned for a
grid of |
localgrid |
Regions at which tests will be performed. Defaults to
dividing each |
nbaseknots |
Number of knots for the spline approximation to the
baseline effect of |
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 |
priorCoef |
Prior on the coefficients, passed on to
|
priorGroup |
Prior on grouped coefficients, passed on to
|
priorDelta |
Prior on the models, passed on to
|
mc.cores |
If package parallel is available on your system and
|
return.mcmc |
Set to |
verbose |
If |
... |
Other arguments to be passed on to |
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.
Object of class localtest
, which extends a list with elements
covareffects |
Estimated local covariate effects at different
|
pplocalgrid |
Posterior probabilities for the existence of an
effect for regions of |
covareffects.mcmc |
MCMC output used to build covareffects. Only
returned if |
ms |
Objects of class |
pp_localknots |
Posterior probability for each resolution level
(value of |
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 |
David Rossell
#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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.