I am relearning all the test I know in SAS.

This is the Breusch-Godfrey Test for serial correlation

This is the R documentation. I think I got it right but I am not sure because I do not ask for the residuals above (this comes from page 2).

bgtest(formula, order = 1, order.by = NULL, type = c("Chisq", "F"),

data = list(), fill = 0)

Arguments

formula a symbolic description for the model to be tested (or a fitted "lm" object).

order integer. maximal order of serial correlation to be tested.

order.by Either a vector z or a formula with a single explanatory variable like ~ z. The

observations in the model are ordered by the size of z. If set to NULL (the default)

the observations are assumed to be ordered (e.g., a time series).

type the type of test statistic to be returned. Either "Chisq" for the Chi-squared test

statistic or "F" for the F test statistic.

data an optional data frame containing the variables in the model. By default the

variables are taken from the environment which bgtest is called from.

https://cran.r-project.org/web/packages/lmtest/lmtest.pdf

the Ramsey RESET test

It concerns me that the p value is so low although this is a made up result. It makes me wonder if I ran the test right.

This is the Breusch-Godfrey Test for serial correlation

Code:

```
data(mtcars)
model <- lm(mpg~disp+hp, data=mtcars)
bgtest(mpg~disp+hp, order = 1,data = mtcars ) #Breusch-Godfrey Test for serial correlation
Breusch-Godfrey test for serial correlation of order up to 1 # results
data: mpg ~ disp + hp
LM test = 3.6211, df = 1, p-value = 0.05705
```

bgtest(formula, order = 1, order.by = NULL, type = c("Chisq", "F"),

data = list(), fill = 0)

Arguments

formula a symbolic description for the model to be tested (or a fitted "lm" object).

order integer. maximal order of serial correlation to be tested.

order.by Either a vector z or a formula with a single explanatory variable like ~ z. The

observations in the model are ordered by the size of z. If set to NULL (the default)

the observations are assumed to be ordered (e.g., a time series).

type the type of test statistic to be returned. Either "Chisq" for the Chi-squared test

statistic or "F" for the F test statistic.

data an optional data frame containing the variables in the model. By default the

variables are taken from the environment which bgtest is called from.

https://cran.r-project.org/web/packages/lmtest/lmtest.pdf

the Ramsey RESET test

Code:

```
It starts in page 36 https://cran.r-project.org/web/packages/lmtest/lmtest.pdf
resettest(formula, power = 2:3, type = c("fitted", "regressor", "princomp"), data = list(), vcov = NULL, ...)
data(mtcars)
model <- lm(mpg~disp+hp, data=mtcars)
resettest(mpg~disp+hp, power = 2:3, data = mtcars) # pulls in cubics and quadratics
RESET test # results
data: mpg ~ disp + hp
RESET = 15.45, df1 = 2, df2 = 27, p-value = 3.367e-05
```

Last edited: