https://github.com/cran/lmtest
Tip revision: cc0d903ae7be9f24d4ed9155ad8ce7df8529f089 authored by Achim Zeileis on 20 April 2013, 00:00:00 UTC
version 0.9-31
version 0.9-31
Tip revision: cc0d903
lmtest-intro.Rout.save
> library(lmtest)
Loading required package: zoo
Attaching package: 'zoo'
The following object(s) are masked from 'package:base':
as.Date, as.Date.numeric
> options(SweaveHooks = list(twofig = function() {
+ par(mfrow = c(1, 2))
+ }, twofig2 = function() {
+ par(mfrow = c(2, 1))
+ }, onefig = fun .... [TRUNCATED]
> data(jocci)
> plot(jocci[, "dy"], ylab = "jocci (log first differences)")
> ar6.model <- dy ~ dy1 + dy2 + dy3 + dy4 + dy5 + dy6
> jocci.fm <- lm(ar6.model, data = jocci)
> plot(time(jocci), residuals(jocci.fm), xlab = "Time",
+ ylab = "AR(6) residuals")
> data(jocci)
> dwtest(dy ~ 1, data = jocci)
Durbin-Watson test
data: dy ~ 1
DW = 1.0581, p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0
> ar6.model <- dy ~ dy1 + dy2 + dy3 + dy4 + dy5 + dy6
> bgtest(ar6.model, data = jocci)
Breusch-Godfrey test for serial correlation of order up to 1
data: ar6.model
LM test = 0.2, df = 1, p-value = 0.6547
> var.model <- ~I(dy1^2) + I(dy2^2) + I(dy3^2) + I(dy4^2) +
+ I(dy5^2) + I(dy6^2)
> bptest(ar6.model, var.model, data = jocci)
studentized Breusch-Pagan test
data: ar6.model
BP = 22.3771, df = 6, p-value = 0.001034
> data(Mandible)
> mandible <- log(Mandible)
> attach(mandible)
> plot(mandible)
> fm <- lm(length ~ age)
> fm2 <- lm(length ~ age + I(age^2))
> lines(age, fitted(fm), col = 2)
> lines(age, fitted(fm2), col = 4)
> plot(age, residuals(fm), ylab = "residuals (linear model)")
> plot(age, residuals(fm2), ylab = "residuals (quadratic model)")
> detach(mandible)
> resettest(length ~ age, data = mandible)
RESET test
data: length ~ age
RESET = 25.6367, df1 = 2, df2 = 163, p-value = 2.086e-10
> resettest(length ~ age, power = 2, type = "regressor",
+ data = mandible)
RESET test
data: length ~ age
RESET = 51.5541, df1 = 1, df2 = 164, p-value = 2.302e-11
> raintest(length ~ age + I(age^2), order.by = ~age,
+ data = mandible)
Rainbow test
data: length ~ age + I(age^2)
Rain = 1.579, df1 = 84, df2 = 80, p-value = 0.02033
> if (require(strucchange)) {
+ supF.pval <- round(sctest(length ~ age + I(age^2), data = mandible,
+ to = 0.9, type = "supF")$p.value, d .... [TRUNCATED]
Loading required package: strucchange
Loading required package: sandwich
*** Run successfully completed ***