selinf: Calculate p-values / confidence intervals after...

Description Usage Arguments Examples

Description

This is a wrapper and convenience function for several functions included in this package. Please see calculate_selinf for more details and how to calculate inference when several model selection procedures are combined. When more than one list is supplied, the best model in the first listOfModels is used to perform inference.

Usage

1
2
selinf(listOfModels, ..., response = NULL, what, REML = FALSE, df = 1, sd,
  alpha = 0.05, gridpts = 500, griddepth = 3, range = 100)

Arguments

listOfModels

a list of models representing one comparison

...

optionally more lists of models representing further comparisons

response

response vector

what

character describing the method, on the basis of which variable selection was performed. Supported variable selection procedures are AIC ("aic"), BIC ("bic"), likelihood-based selection ("llonly") and significance tests based on the likelihood-ratio or the F-statistic ("lrt", "Ftest"). If different selection procedures have been used, please supply the corresponding character for each list of models.

REML

logical; whether scale estimates should be calculated via REML or not. Default is FALSE since the log-likelihood is calculated with REML=FALSE by the logLik function.

df

positive integer; defines the degree of freedom when using the likelihood ratio test for model selection. Defaults to 1 (testing one parameter at a time).

sd

standard deviation of error used for the p-value calculation (see details)

alpha

value for (1-alpha)-confidence interval construction. Defaults to 0.05.

gridpts, griddepth, range

options for the calculation of confidence intervals. See ci_tnorm for more details.

Examples

 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
library(MASS)
data("cpus")
# Fit initial model
cpus$perf <- log10(cpus$perf)
cpus$cach <- as.factor(cpus$cach)
mod <- lm(perf ~ .-name, data = cpus)

# use the stepAIC function to find the best model in a backward 
# stepwise search
cpus.lm <- stepAIC(mod, trace = FALSE, direction = "backward", steps = 3)
# check model selection
cpus.lm$anova$Step

# recalculate all visited models in the first step
lom1 <- c(lapply(attr(mod$terms, "term.labels"), function(x) 
update(mod, as.formula(paste0("perf ~ .-", x)))), list(mod))

# perform likelihood ratio test at level 
alpha = 0.001

# check for non-significant variables
coefTable <- anova(cpus.lm)
drop <- rownames(coefTable)[alpha < coefTable[-nrow(coefTable),5]]

# drop non-significant variable
cpus.lm2 <- update(cpus.lm, as.formula(paste0(".~.-",drop)))

# compute selective inference
selinf(list(cpus.lm, cpus.lm2), lom1, 
response = cpus$perf,
what = c("Ftest", "aic"),
sd = summary(cpus.lm2)$sigma)

davidruegamer/coinflibs documentation built on May 14, 2019, 10:33 a.m.