wald: General Linear Hypothesis for the 'fixed' portion of a model...

Description Usage Arguments Details Value Functions References See Also Examples

Description

General Linear Hypothesis with Wald test for lm, glm, lme, nlme and lmer objects. Can be extended to other objects (e.g.) 'glm' by writing 'getFix.glm'

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
wald(fit, Llist = "", clevel = 0.95, data = NULL, debug = FALSE,
  maxrows = 25, full = FALSE, fixed = FALSE, invert = FALSE,
  method = "svd", df = NULL)

wald2(fit, Llist = "", clevel = 0.95, data = NULL, debug = FALSE,
  maxrows = 25, full = FALSE, fixed = FALSE, invert = FALSE,
  method = "svd", df = NULL, RHS = 0)

wald.transform(x, fun, label = "Transformed coefficients")

glh(...)

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

data

data frame used as 'data' attribute fot list elements returned only if the corresonding 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

if Llist is a character to be used 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 to be used 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.

help

obsolete

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' a regular expression (see ?regex) used to match names of coefficients of fixed effects. e.g. wald( fit, ':.*:') tests all 2nd 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

There are number of functions to help construct hypothesis matrices. See in particular Lfx.

# 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. The getFix method for # glm objects is:

getFix.glm <- function(fit,...) ss <- summary(fit) ret <- list() ret$fixed <- coef(fit) ret$vcov <- vcov(fit) ret$df <- rep(ss$df.residual, length(ret$fixed)) ret

# and for 'mipo' objects in the packages 'mice':

getFix.mipo <- function( fit, ...) # # pooled multiple imputation object in mice # 'wald' will use the minimal df for components with non-zero weights # – this is probably too conservative and should be improved # ret <- list() ret$fixed <- fit$qbar ret$vcov <- fit$t ret$df <- fit$df ret

Value

An object of class wald, with the following components: COMPLETE

Functions

References

REFERENCES HERE

See Also

Lform, xlevels, dlevels, Lfx, getX, M, Lall,Lc,Lequal, Ldiff,Lmu,Lmat,Lrm, Leff, as.data.frame.wald. To extend to new models see getFix. To generate hypothesis matrices for general splines see gsp and sc.

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
data(hs)
library( nlme )

###
### Using wald to create and plot a data frame with predicted values
###
  fit <- lme(mathach ~ (ses+I(ses^2)) * Sex * Sector, hs, random = ~ 1|school)
  summary(fit)
  pred <- expand.grid( ses = seq(-2,2,.1), Sex = levels(hs$Sex), Sector = levels(hs$Sector))
  pred
  w <- wald(fit, getX(fit,data=pred)) # attaches data to wald.object so it can included in data frame
  w
  w <- as.data.frame(w)
  head(w)
  library(latticeExtra)
  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), hs)
L
(ww <- wald ( fit, L ))
wald.dd <- as.data.frame(ww, se = 2)
head( wald.dd )

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

gmonette/spidanew documentation built on May 17, 2019, 7:27 a.m.