Description Usage Arguments Details Value Examples
Function which computes selective p-values and intervals for gamm4
and
merMod
objects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | mocasin(
mod,
checkFun,
this_y = NULL,
nrSamples = 1000,
bayesian = TRUE,
varInTestvec = c("est", "minMod", "varY", "supplied"),
varForSampling = c("est", "minMod", "varY", "supplied"),
VCOV_vT = NULL,
VCOV_sampling = NULL,
conditional = TRUE,
name = NULL,
nrlocs = 7,
complete_effect = NULL,
which = NULL,
vT = NULL,
G = NULL,
efficient = TRUE,
trace = TRUE
)
|
mod |
an object of class |
checkFun |
a function of |
this_y |
original response vector (explicit reference may be necessary for certain model classes) |
nrSamples |
integer; the number of Monte Carlo samples to be used for inference (defaults to 1000) |
bayesian |
logical; whether or not to use a bayesian type covariance |
varInTestvec |
for expert use only; variance used in the test vector definition |
varForSampling |
variance used for inference; per default the estimated variance
of |
VCOV_vT |
for expert use only; VCOV used in the test vector definition |
VCOV_sampling |
covariance matrix of dimension of the response used for inference;
per default the estimated covariance of |
conditional |
logical; determines whether to use the conditional or
marginal approach
when |
name |
character; for the |
nrlocs |
integer; for the |
complete_effect |
list of logical values for each |
which |
integer; for the |
vT |
list of vectors (optional); if inference is sought for a customized test vector, this argument can be used |
G |
true random effect covariance (optional) |
efficient |
logical; whether or not to compute the test statistic based on an (efficient) weighted LS estimator instead of a OLS estimator for the marginal model |
trace |
logical; if TRUE, a progress bar is printed in the console |
Note that the additive and conditional mixed model approach currently only works for a diagonal error covariance.
An object of class selfmade
with corresponding print
method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | library(lme4)
if(require(lmerTest)){
##### BASED ON lmerTest HELP PAGE #########
# define function to fit a model based on response
modFun <- function(y)
{
ham$y <- y
lmer(y ~ Gender + Information * Product + (1 | Consumer) +
(1 | Product), data=ham)
}
# define a function to select a model (based on a model)
selFun <- function(mod) step(mod)
# define a function which extracts the results of the selection procedure
extractSelFun <- function(this_mod){
this_mod <- attr(this_mod, "model")
if(class(this_mod)=="lm")
return(attr(this_mod$coefficients, "names")) else
return(c(names(fixef(this_mod)), names(getME(this_mod, "theta"))))
}
## backward elimination of non-significant effects:
(step_result <- selFun(modFun(ham$Informed.liking)))
attr(step_result, "model")
## Elimination tables for random- and fixed-effect terms:
(sel <- extractSelFun(step_result))
## Now we can finally define the function checking the congruency
## with the original selection
checkFun <- function(yb){
this_mod <- modFun(yb)
setequal( extractSelFun(selFun(this_mod)), sel )
}
# Now let's compute valid p-values conditional on the selection
## Not run:
res <- mocasin(attr(step_result, "model"), this_y = ham$Informed.liking,
checkFun = checkFun, which = 1, nrSamples = 8, trace = FALSE)
# print(res)
## End(Not run)
}
# gamm4 example similar to the one from gamm4 help page
if(require(gamm4)){
set.seed(0)
dat <- gamSim(1, n = 500, scale = 2) ## simulate 4 term additive truth
dat$y <- 3 + dat$x0^2 + rnorm(n = 500)
br <- gamm4(y~ s(x0) + s(x1), data = dat)
summary(br$gam) ## summary of gam
# do not use any selection
checkFun <- function(yb) TRUE
## Not run:
res <- mocasin(br, this_y = dat$y,
checkFun = checkFun,
nrlocs = c(0.7),
nrSamples = 100)
# print result
res
## End(Not run)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.