WaldTest | R Documentation |
Use a contrast matrix to test several linear hypotheses on the coefficients using a Wald test. The hypotheses are assumed to be independent of each other.
WaldTest(object, ...)
## S3 method for class 'gls'
WaldTest(object, C, b = rep(0, NROW(C)), df = NULL, ...)
## S3 method for class 'lme'
WaldTest(object, C, b = rep(0, NROW(C)), df = NULL, ...)
object |
a model. Currently only support |
... |
not used. |
C |
a contrast matrix. Number of rows is the number of hypotheses. Number of columns should match the number of coefficients in the model. |
b |
a vector such that the hypothesis to test is: |
df |
[optional] the degree of freedom associated to the variance of each coefficient. |
Denoting \beta
the estimated model coefficients,
Sigma
their estimated variance covariance matrix,
and t()
the transpose operator, this function computes:
Cb = C * \beta
CSC = C * \Sigma * t(C)
t = \sqrt{Cb/diag(CSC)}
and compute the p.value using the Gaussian distribution (df=NULL
) or a student's t-distribution.
In such a case the degrees of freedom are computed using:
Cdf = C * df
This formula is probably a very crude approximation to the appropriate degrees of freedom of diag(CSC)
(assuming they exists).
library(nlme)
## gls
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary,
correlation = corAR1(form = ~ 1 | Mare))
name.coef <- names(coef(fm1))
n.coef <- length(name.coef)
C <- matrix(0, nrow = n.coef, ncol = n.coef,
dimnames = list(name.coef, name.coef))
diag(C) <- 1
WaldTest(fm1, C)
summary(fm1)$tTable
## lme
fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
name.coef <- names(coef(fm2))
n.coef <- length(name.coef)
C <- matrix(0, nrow = n.coef, ncol = n.coef,
dimnames = list(name.coef, name.coef))
diag(C) <- 1
WaldTest(fm2, C)
summary(fm2)$tTable
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.