wald {carEx} | R Documentation |
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.
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, ...)
fit |
a model for which a |
Llist |
a hypothesis matrix or a pattern to be matched or a list of these. |
clevel |
level for confidence intervals. No confidence intervals if |
pred |
(default |
data |
data frame used as |
debug |
(default |
maxrows |
maximum number of rows of hypothesis matrix for which a full variance-covariance matrix is returned |
full |
if |
fixed |
normally if |
invert |
if |
method |
|
pars |
passed to |
x |
a |
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 |
which |
which element(s) of a |
row.names |
optional row names for the resulting data frame. |
..., optional |
to match generic, ignored. |
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.
An object of class wald
.
Georges Monette
To extend to new models see getFix
. To generate hypothesis matrices for general
splines see gspline
.
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")){ xyplot(coef ~ SES | Sector, w, groups = Sex, auto.key = TRUE, type = 'l', fit = w$coef, upper = with(w,coef+2*se), lower = with(w,coef-2*se), subscript = TRUE) + glayer(panel.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') } }