lmtest: Interfaces for lmtest package for data science pipelines.

Description Usage Arguments Details Value Author(s) Examples

Description

Interfaces to lmtest functions that can be used in a pipeline implemented by magrittr.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12

Arguments

data

data frame, tibble, list, ...

...

Other arguments passed to the corresponding interfaced function.

Details

Interfaces call their corresponding interfaced function.

Value

Object returned by interfaced function.

Author(s)

Roberto Bertolusso

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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
## Not run: 
library(intubate)
library(magrittr)
library(lmtest)

## ntbt_bgtest: Breusch-Godfrey Test for higher-order serial correlation
x <- rep(c(1, -1), 50)
y1 <- 1 + x + rnorm(100)
dta <- data.frame(x, y1)

## or for fourth-order serial correlation
## Original function to interface
bgtest(y1 ~ x, order = 4, data = dta)

## The interface puts data as first parameter
ntbt_bgtest(dta, y1 ~ x, order = 4)

## so it can be used easily in a pipeline.
dta %>%
  ntbt_bgtest(y1 ~ x, order = 4)


## ntbt_bptest: Breusch-Pagan test against heteroskedasticity
## ntbt_gqtest: Goldfeld-Quandt test against heteroskedasticity
## ntbt_hmctest: Harrison-McCabe test for heteroskedasticity
x <- rep(c(-1,1), 50)
err1 <- c(rnorm(50, sd=1), rnorm(50, sd=2))
err2 <- rnorm(100)
y1 <- 1 + x + err1
y2 <- 1 + x + err2
dtah <- data.frame(x, y1, y2)

## Original function to interface
bptest(y1 ~ x, data = dtah)
gqtest(y1 ~ x, data = dtah)
hmctest(y1 ~ x, data = dtah)
bptest(y2 ~ x, data = dtah)
gqtest(y2 ~ x, data = dtah)
hmctest(y2 ~ x, data = dtah)

## The interface puts data as first parameter
ntbt_bptest(dtah, y1 ~ x)
ntbt_gqtest(dtah, y1 ~ x)
ntbt_hmctest(dtah, y1 ~ x)
ntbt_bptest(dtah, y2 ~ x)
ntbt_gqtest(dtah, y2 ~ x)
ntbt_hmctest(dtah, y2 ~ x)

## so it can be used easily in a pipeline.
dtah %>%
  ntbt_bptest(y1 ~ x)
dtah %>%
  ntbt_gqtest(y1 ~ x)
dtah %>%
  ntbt_hmctest(y1 ~ x)
dtah %>%
  ntbt_bptest(y2 ~ x)
dtah %>%
  ntbt_gqtest(y2 ~ x)
dtah %>%
  ntbt_hmctest(y2 ~ x)


## ntbt_coxtest: Cox Test for Comparing Non-Nested Models
## ntbt_encomptest: encompassing test of Davidson & MacKinnon for comparing non-nested models
## ntbt_jtest: Davidson-MacKinnon J test for comparing non-nested models
data(USDistLag)
usdl <- na.contiguous(cbind(USDistLag, lag(USDistLag, k = -1)))
colnames(usdl) <- c("con", "gnp", "con1", "gnp1")

## Original function to interface
coxtest(con ~ gnp + con1, con ~ gnp + gnp1, data = usdl)
encomptest(con ~ gnp + con1, con ~ gnp + gnp1, data = usdl)
jtest(con ~ gnp + con1, con ~ gnp + gnp1, data = usdl)

## The interface puts data as first parameter
ntbt_coxtest(usdl, con ~ gnp + con1, con ~ gnp + gnp1)
ntbt_encomptest(usdl, con ~ gnp + con1, con ~ gnp + gnp1)
ntbt_jtest(usdl, con ~ gnp + con1, con ~ gnp + gnp1)

## so it can be used easily in a pipeline.
usdl %>%
  ntbt_coxtest(con ~ gnp + con1, con ~ gnp + gnp1)
usdl %>%
  ntbt_encomptest(con ~ gnp + con1, con ~ gnp + gnp1)
usdl %>%
  ntbt_jtest(con ~ gnp + con1, con ~ gnp + gnp1)

## ntbt_dwtest: Durbin-Watson test for autocorrelation of disturbances
err1 <- rnorm(100)
x <- rep(c(-1,1), 50)
y1 <- 1 + x + err1
err2 <- filter(err1, 0.9, method="recursive")
y2 <- 1 + x + err2
dta <- data.frame(y1, y2, x)

## Original function to interface
dwtest(y1 ~ x, data = dta)
dwtest(y2 ~ x, data = dta)

## The interface puts data as first parameter
ntbt_dwtest(dta, y1 ~ x)
ntbt_dwtest(dta, y2 ~ x)

## so it can be used easily in a pipeline.
dta %>%
  ntbt_dwtest(y1 ~ x)
dta %>%
  ntbt_dwtest(y2 ~ x)


## ntbt_grangertest: Test for Granger Causality
data(ChickEgg)
## Original function to interface
grangertest(egg ~ chicken, order = 3, data = ChickEgg)
grangertest(chicken ~ egg, order = 3, data = ChickEgg)

## The interface puts data as first parameter
ntbt_grangertest(ChickEgg, egg ~ chicken, order = 3)
ntbt_grangertest(ChickEgg, chicken ~ egg, order = 3)

## so it can be used easily in a pipeline.
ChickEgg %>%
  ntbt_grangertest(egg ~ chicken, order = 3)
ChickEgg %>%
  ntbt_grangertest(chicken ~ egg, order = 3)


## ntbt_harvtest: Harvey-Collier test for linearity
x <- 1:50
y1 <- 1 + x + rnorm(50)
y2 <- y1 + 0.3*x^2
dta <- data.frame(y1, x)

## Original function to interface
harvtest(y1 ~ x, data = dta)

## The interface puts data as first parameter
ntbt_harvtest(dta, y1 ~ x)

## so it can be used easily in a pipeline.
dta %>%
  ntbt_harvtest(y1 ~ x)

## ntbt_raintest: Rainbow test for linearity
x <- c(1:30)
y <- x^2 + rnorm(30,0,2)
dta <- data.frame(x, y)

## Original function to interface
raintest(y ~ x, data = dta)

## The interface puts data as first parameter
ntbt_raintest(dta, y ~ x)

## so it can be used easily in a pipeline.
dta %>%
  ntbt_raintest(y ~ x)


## ntbt_resettest: Ramsey's RESET test for functional form
x <- c(1:30)
y1 <- 1 + x + x^2 + rnorm(30)
y2 <- 1 + x + rnorm(30)
dta <- data.frame(x, y1, y2)

## Original function to interface
resettest(y1 ~ x , power=2, type="regressor", data = dta)
resettest(y2 ~ x , power=2, type="regressor", data = dta)

## The interface puts data as first parameter
ntbt_resettest(dta, y1 ~ x , power=2, type="regressor")
ntbt_resettest(dta, y2 ~ x , power=2, type="regressor")

## so it can be used easily in a pipeline.
dta %>%
  ntbt_resettest(y1 ~ x , power=2, type="regressor")
dta %>%
  ntbt_resettest(y2 ~ x , power=2, type="regressor")

## End(Not run)

Example output

Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric


	Breusch-Godfrey test for serial correlation of order up to 4

data:  y1 ~ x
LM test = 2.5801, df = 4, p-value = 0.6304


	Breusch-Godfrey test for serial correlation of order up to 4

data:  y1 ~ x
LM test = 2.5801, df = 4, p-value = 0.6304


	Breusch-Godfrey test for serial correlation of order up to 4

data:  y1 ~ x
LM test = 2.5801, df = 4, p-value = 0.6304


	studentized Breusch-Pagan test

data:  y1 ~ x
BP = 0.019081, df = 1, p-value = 0.8901


	Goldfeld-Quandt test

data:  y1 ~ x
GQ = 6.4967, df1 = 48, df2 = 48, p-value = 7.012e-10
alternative hypothesis: variance increases from segment 1 to 2


	Harrison-McCabe test

data:  y1 ~ x
HMC = 0.13722, p-value < 2.2e-16


	studentized Breusch-Pagan test

data:  y2 ~ x
BP = 0.0031537, df = 1, p-value = 0.9552


	Goldfeld-Quandt test

data:  y2 ~ x
GQ = 0.91157, df1 = 48, df2 = 48, p-value = 0.6251
alternative hypothesis: variance increases from segment 1 to 2


	Harrison-McCabe test

data:  y2 ~ x
HMC = 0.523, p-value = 0.647


	studentized Breusch-Pagan test

data:  y1 ~ x
BP = 0.019081, df = 1, p-value = 0.8901


	Goldfeld-Quandt test

data:  y1 ~ x
GQ = 6.4967, df1 = 48, df2 = 48, p-value = 7.012e-10
alternative hypothesis: variance increases from segment 1 to 2


	Harrison-McCabe test

data:  y1 ~ x
HMC = 0.13722, p-value < 2.2e-16


	studentized Breusch-Pagan test

data:  y2 ~ x
BP = 0.0031537, df = 1, p-value = 0.9552


	Goldfeld-Quandt test

data:  y2 ~ x
GQ = 0.91157, df1 = 48, df2 = 48, p-value = 0.6251
alternative hypothesis: variance increases from segment 1 to 2


	Harrison-McCabe test

data:  y2 ~ x
HMC = 0.523, p-value = 0.636


	studentized Breusch-Pagan test

data:  y1 ~ x
BP = 0.019081, df = 1, p-value = 0.8901


	Goldfeld-Quandt test

data:  y1 ~ x
GQ = 6.4967, df1 = 48, df2 = 48, p-value = 7.012e-10
alternative hypothesis: variance increases from segment 1 to 2


	Harrison-McCabe test

data:  y1 ~ x
HMC = 0.13722, p-value < 2.2e-16


	studentized Breusch-Pagan test

data:  y2 ~ x
BP = 0.0031537, df = 1, p-value = 0.9552


	Goldfeld-Quandt test

data:  y2 ~ x
GQ = 0.91157, df1 = 48, df2 = 48, p-value = 0.6251
alternative hypothesis: variance increases from segment 1 to 2


	Harrison-McCabe test

data:  y2 ~ x
HMC = 0.523, p-value = 0.62

Cox test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
                Estimate Std. Error z value  Pr(>|z|)    
fitted(M1) ~ M2   2.8543    1.29978  2.1960   0.02809 *  
fitted(M2) ~ M1  -4.4003    0.78961 -5.5727 2.508e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Encompassing test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
Model E: con ~ gnp + con1 + gnp1
          Res.Df Df      F    Pr(>F)    
M1 vs. ME     15 -1 12.569 0.0029371 ** 
M2 vs. ME     15 -1 27.093 0.0001067 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
J test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
                Estimate Std. Error t value  Pr(>|t|)    
M1 + fitted(M2)  -2.7041    0.76273 -3.5454 0.0029371 ** 
M2 + fitted(M1)   2.7436    0.52710  5.2051 0.0001067 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Cox test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
                Estimate Std. Error z value  Pr(>|z|)    
fitted(M1) ~ M2   2.8543    1.29978  2.1960   0.02809 *  
fitted(M2) ~ M1  -4.4003    0.78961 -5.5727 2.508e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Encompassing test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
Model E: con ~ gnp + con1 + gnp1
          Res.Df Df      F    Pr(>F)    
M1 vs. ME     15 -1 12.569 0.0029371 ** 
M2 vs. ME     15 -1 27.093 0.0001067 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
J test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
                Estimate Std. Error t value  Pr(>|t|)    
M1 + fitted(M2)  -2.7041    0.76273 -3.5454 0.0029371 ** 
M2 + fitted(M1)   2.7436    0.52710  5.2051 0.0001067 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Cox test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
                Estimate Std. Error z value  Pr(>|z|)    
fitted(M1) ~ M2   2.8543    1.29978  2.1960   0.02809 *  
fitted(M2) ~ M1  -4.4003    0.78961 -5.5727 2.508e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Encompassing test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
Model E: con ~ gnp + con1 + gnp1
          Res.Df Df      F    Pr(>F)    
M1 vs. ME     15 -1 12.569 0.0029371 ** 
M2 vs. ME     15 -1 27.093 0.0001067 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
J test

Model 1: con ~ gnp + con1
Model 2: con ~ gnp + gnp1
                Estimate Std. Error t value  Pr(>|t|)    
M1 + fitted(M2)  -2.7041    0.76273 -3.5454 0.0029371 ** 
M2 + fitted(M1)   2.7436    0.52710  5.2051 0.0001067 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

	Durbin-Watson test

data:  y1 ~ x
DW = 1.8977, p-value = 0.3388
alternative hypothesis: true autocorrelation is greater than 0


	Durbin-Watson test

data:  y2 ~ x
DW = 0.23539, p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0


	Durbin-Watson test

data:  y1 ~ x
DW = 1.8977, p-value = 0.3388
alternative hypothesis: true autocorrelation is greater than 0


	Durbin-Watson test

data:  y2 ~ x
DW = 0.23539, p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0


	Durbin-Watson test

data:  y1 ~ x
DW = 1.8977, p-value = 0.3388
alternative hypothesis: true autocorrelation is greater than 0


	Durbin-Watson test

data:  y2 ~ x
DW = 0.23539, p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0

Granger causality test

Model 1: egg ~ Lags(egg, 1:3) + Lags(chicken, 1:3)
Model 2: egg ~ Lags(egg, 1:3)
  Res.Df Df      F Pr(>F)
1     44                 
2     47 -3 0.5916 0.6238
Granger causality test

Model 1: chicken ~ Lags(chicken, 1:3) + Lags(egg, 1:3)
Model 2: chicken ~ Lags(chicken, 1:3)
  Res.Df Df     F   Pr(>F)   
1     44                     
2     47 -3 5.405 0.002966 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Granger causality test

Model 1: egg ~ Lags(egg, 1:3) + Lags(chicken, 1:3)
Model 2: egg ~ Lags(egg, 1:3)
  Res.Df Df      F Pr(>F)
1     44                 
2     47 -3 0.5916 0.6238
Granger causality test

Model 1: chicken ~ Lags(chicken, 1:3) + Lags(egg, 1:3)
Model 2: chicken ~ Lags(chicken, 1:3)
  Res.Df Df     F   Pr(>F)   
1     44                     
2     47 -3 5.405 0.002966 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Granger causality test

Model 1: egg ~ Lags(egg, 1:3) + Lags(chicken, 1:3)
Model 2: egg ~ Lags(egg, 1:3)
  Res.Df Df      F Pr(>F)
1     44                 
2     47 -3 0.5916 0.6238
Granger causality test

Model 1: chicken ~ Lags(chicken, 1:3) + Lags(egg, 1:3)
Model 2: chicken ~ Lags(chicken, 1:3)
  Res.Df Df     F   Pr(>F)   
1     44                     
2     47 -3 5.405 0.002966 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

	Harvey-Collier test

data:  y1 ~ x
HC = 0.45652, df = 47, p-value = 0.6501


	Harvey-Collier test

data:  y1 ~ x
HC = 0.45652, df = 47, p-value = 0.6501


	Harvey-Collier test

data:  y1 ~ x
HC = 0.45652, df = 47, p-value = 0.6501


	Rainbow test

data:  y ~ x
Rain = 28.868, df1 = 15, df2 = 13, p-value = 1.577e-07


	Rainbow test

data:  y ~ x
Rain = 28.868, df1 = 15, df2 = 13, p-value = 1.577e-07


	Rainbow test

data:  y ~ x
Rain = 28.868, df1 = 15, df2 = 13, p-value = 1.577e-07


	RESET test

data:  y1 ~ x
RESET = 123550, df1 = 1, df2 = 27, p-value < 2.2e-16


	RESET test

data:  y2 ~ x
RESET = 0.47418, df1 = 1, df2 = 27, p-value = 0.4969


	RESET test

data:  y1 ~ x
RESET = 123550, df1 = 1, df2 = 27, p-value < 2.2e-16


	RESET test

data:  y2 ~ x
RESET = 0.47418, df1 = 1, df2 = 27, p-value = 0.4969


	RESET test

data:  y1 ~ x
RESET = 123550, df1 = 1, df2 = 27, p-value < 2.2e-16


	RESET test

data:  y2 ~ x
RESET = 0.47418, df1 = 1, df2 = 27, p-value = 0.4969

intubate documentation built on May 2, 2019, 2:46 p.m.