Learn R Programming

lavaSearch2 (version 1.4)

compare2: Test Linear Hypotheses with small sample correction

Description

Test Linear Hypotheses using a multivariate Wald statistic. Similar to lava::compare but with small sample correction.

Usage

compare2(object, df, bias.correct, ...)

# S3 method for lm compare2(object, df = TRUE, bias.correct = TRUE, ...)

# S3 method for gls compare2(object, df = TRUE, bias.correct = TRUE, cluster = NULL, ...)

# S3 method for lme compare2(object, df = TRUE, bias.correct = TRUE, ...)

# S3 method for lvmfit compare2(object, df = TRUE, bias.correct = TRUE, cluster = NULL, ...)

# S3 method for lm2 compare2(object, ...)

# S3 method for gls2 compare2(object, ...)

# S3 method for lme2 compare2(object, ...)

# S3 method for lvmfit2 compare2(object, ...)

.compare2(object, par = NULL, contrast = NULL, null = NULL, rhs = NULL, robust = FALSE, cluster = NULL, df = TRUE, as.lava = TRUE, F.test = TRUE, level = 0.95)

Arguments

object

an object that inherits from lm/gls/lme/lvmfit.

df

[logical] should the degree of freedoms of the Wald statistic be computed using the Satterthwaite correction? Otherwise the degree of freedoms are set to Inf, i.e. a normal distribution is used instead of a Student's t distribution when computing the p-values.

bias.correct

[logical] should the standard errors of the coefficients be corrected for small sample bias? Argument passed to sCorrect.

...

[internal] only used by the generic method.

cluster

[integer vector] the grouping variable relative to which the observations are iid.

par

[vector of characters] expression defining the linear hypotheses to be tested. See the examples section.

contrast

[matrix] a contrast matrix defining the left hand side of the linear hypotheses to be tested.

null, rhs

[vector] the right hand side of the linear hypotheses to be tested.

robust

[logical] should the robust standard errors be used instead of the model based standard errors?

as.lava

[logical] should the output be similar to the one return by lava::compare?

F.test

[logical] should a joint test be performed?

level

[numeric 0-1] the confidence level of the confidence interval.

Value

If as.lava=TRUE an object of class htest. Otherwise a data.frame object.

Details

The par argument or the arguments contrast and null (or equivalenty rhs) specify the set of linear hypotheses to be tested. They can be written: $$ contrast * \theta = null $$ where \(\theta\) is the vector of the model coefficients. The par argument must contain expression(s) involving the model coefficients. For example "beta = 0" or c("-5*beta + alpha = 3","-alpha") are valid expressions if alpha and beta belong to the set of model coefficients. A contrast matrix and the right hand side will be generated inside the function.

When directly specified, the contrast matrix must contain as many columns as there are coefficients in the model (mean and variance coefficients). Each hypothesis correspond to a row in the contrast matrix.

The null vector should contain as many elements as there are row in the contrast matrix.

Argument rhs and null are equivalent. This redondance enable compatibility between lava::compare, compare2, multcomp::glht, and glht2.

See Also

createContrast to create contrast matrices. sCorrect to pre-compute quantities for the small sample correction.

Examples

Run this code
# NOT RUN {
#### simulate data ####
set.seed(10)
mSim <- lvm(Y~0.1*X1+0.2*X2)
categorical(mSim, labels = c("a","b","c")) <- ~X1
transform(mSim, Id~Y) <- function(x){1:NROW(x)}
df.data <- lava::sim(mSim, 1e2)

#### with lm ####
## direct use of compare2
e.lm <- lm(Y~X1+X2, data = df.data)
anova(e.lm)
compare2(e.lm, par = c("X1b=0","X1c=0"))

## or first compute the derivative of the information matrix
sCorrect(e.lm) <- TRUE

## and define the contrast matrix
C <- createContrast(e.lm, par = c("X1b=0","X1c=0"), add.variance = TRUE)

## run compare2
compare2(e.lm, contrast = C$contrast, null = C$null)
compare2(e.lm, contrast = C$contrast, null = C$null, robust = TRUE)

#### with gls ####
library(nlme)
e.gls <- gls(Y~X1+X2, data = df.data, method = "ML")

## first compute the derivative of the information matrix
sCorrect(e.gls, cluster = 1:NROW(df.data)) <- TRUE

compare2(e.gls, par = c("5*X1b+2*X2 = 0","(Intercept) = 0"))

#### with lvm ####
m <- lvm(Y~X1+X2)
e.lvm <- estimate(m, df.data)

compare2(e.lvm, par = c("-Y","Y~X1b+Y~X1c"))
# }

Run the code above in your browser using DataLab