wald: Wald Test of a General Linear Hypothesis for the 'Fixed'...

Description Usage Arguments Details Value Author(s) See Also Examples

Description

General Linear Hypothesis with Wald test for, e.g., lm, glm, lme, nlme and lmer objects. Can be extended to other classes by writing an appropriate getFix method.

Usage

1
2
3
4
5
6
7
8
9
wald(fit, Llist = "", clevel = 0.95, pred = NULL, data = NULL,
  debug = FALSE, maxrows = 25, full = FALSE, fixed = FALSE,
  invert = FALSE, method = "svd", df = NULL, pars = NULL, ...)
  
## S3 method for class 'wald'
as.data.frame(x, row.names=NULL, optional, se=2, digits=3, sep = "", which=1, ...)

## S3 method for class 'wald'
print(x, round=6, ...) 

Arguments

fit

a model for which a getFix method exists.

Llist

a hypothesis matrix or a pattern to be matched or a list of these.

clevel

level for confidence intervals. No confidence intervals if clevel is NULL.

pred

(default NULL) a data frame to use to create a model matrix. This is an alternative to 'full' when the model matrix needs to be based on a data frame other than the data frame used for fitting the model.

data

data frame used as "data" attribute fot list elements returned only if the corresponding element of Llist has a NULL data attribute

debug

(default FALSE) produce verbose information

maxrows

maximum number of rows of hypothesis matrix for which a full variance-covariance matrix is returned

full

if TRUE, the hypothesis matrix is the model matrix for fit such that the estimated coefficients are the predicted values for the fixed portion of the model. This is designed to allow the calculation of standard errors for models for which the predict method does not provide them.

fixed

normally if Llist is a character string, it's treated as a regular expression; if fixed is TRUE, Llist is interpreted literally, i.e., characters that have a special meaning in regular expressions are interpreted literally.

invert

if Llist is a character string to be used as a regular expression, invert == TRUE causes the matches to be inverted so that coefficients that do not match will be selected.

method

"svd" (current default) or "qr" is the method used to find the full rank version of the hypothesis matrix. ("svd" has correctly identified the rank of a large hypothesis matrix where "qr" has failed.)

pars

passed to extract for "stanfit" objects.

x

a "wald" object.

df

denominator degrees of freedom (overrides usual value).

se

multiplier (default 2) for standard errors in computing confidence limits.

digits, round

number of digits to the right of the decimal.

sep

separator character, for creating names, default is "" (no separator).

which

which element(s) of a "wald" object to convert to a data frame.

row.names

optional row names for the resulting data frame.

..., optional

to match generic, ignored.

Details

Tests a general linear hypothesis for the linear fixed portion of a model. The hypothesis can be specified in a variety of ways such as a hypothesis matrix or a pattern that is used as a regular expression to be matched with the names of coefficients of the model. A number of tools are available to facilitate the generation of hypothesis matrices.

Usage:

wald(fit, L) where L is a hypothesis matrix

wald(fit, "pat") where "pat" is a regular expression (see regex) used to match names of coefficients of fixed effects. e.g. wald( fit, ":.*:") tests all second and higher order interactions.

wald(fit, c(2, 5, 6)) to test 2nd, 5th and 6th coefficients.

wald(fit, list(hyp1 = c(2, 5, 6), H2 = "pat")) for more than one hypothesis matrix.

To extend the wald function to a new class of objects, one needs to write a getFix method to extract estimated coefficients, their estimated covariance matrix, and the denominator degrees of freedom for each estimated coefficient.

Value

An object of class wald.

Author(s)

Georges Monette

See Also

To extend to new models see getFix. To generate hypothesis matrices for general splines see gspline.

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
33
34
35
36
37
38
39
40
41
42
if (require(nlme)){
###
### Using wald to create and plot a data frame with predicted values
###
MathAchieve$Sector <- MathAchSchool[as.character(MathAchieve$School), "Sector"]
fit <- lme(MathAch ~ (SES+I(SES^2)) * Sex * Sector, MathAchieve, random = ~ 1|School)
S(fit)
pred <- expand.grid( SES = seq(-2,2,.1), Sex = levels(MathAchieve$Sex), 
Sector = levels(MathAchieve$Sector))
pred
w <- wald(fit, getX(fit,data=pred)) # attaches data to wald.object 
                                    # so it can be included in data frame
w <- wald(fit, pred = pred)
w <- as.data.frame(w)
head(w)
# if(require("latticeExtra")){  # FIXME (need gpanel.fit from spida2)
#     xyplot(coef ~ SES | Sector, w, groups = Sex,
#            auto.key = T, type = 'l',
#            fit = w$coef,
#            upper = with(w,coef+2*se),
#            lower = with(w,coef-2*se),
#            subscript = T) +
#         glayer( gpanel.fit(...))
# }

wald( fit, 'Sex')  # sig. overall effect of Sex
wald( fit, ':Sex') # but no evidence of interaction with ses
wald( fit, '\\^2') # nor of curvature

# but we continue for the sake of illustration

L <- Lform( fit, list( 0, 1, 2*SES, 0, Sex == 'Male', (Sex == 'Male')*2*SES), MathAchieve)
head(L)
(ww <- wald ( fit, L ))
wald.dd <- as.data.frame(ww, se = 2)
head( wald.dd )

if (require("lattice")){
  xyplot(coef + U2 + L2 ~ SES | Sex, wald.dd,
         main= 'Increase in predicted mathach per unit increase in ses')
}
}

carEx documentation built on June 28, 2019, 3:01 p.m.