| test.linear | R Documentation |
This function performs the regression equation specification error (RESET) test (Remsey, 1969), the Harvey-Collier test (Harvey & Collier, 1977), and the rainbow test for linearity (Utts, 1982). By default, the function performs the RESET test.
test.linear(model, method = c("reset", "harv", "rain"), power = c(2, 3),
frac = 0.5, order = c("none", "all", "mahalanobis"), p.adj = "none",
digits = 2, p.digits = 3, plot = FALSE,
geom = c("all", "none", "lm", "loess", "ci.lm", "ci.loess"),
filename = NULL, width = NA, height = NA, dpi = 600,
write = NULL, append = TRUE, check = TRUE, output = TRUE, ...)
model |
a fitted model of class |
method |
a character string indicating the method used for testing
linearity, i.e., |
power |
a positive integer vector indicating the powers of the
fitted values that should be included in the auxiliary
regression model. By default, the test includes quadratic
and cubic terms in the model, i.e., |
frac |
a numeric value between 0 and 1 indicating the proportion of observations used in the central subset model. Note that this argument is only used for the rainbow test. |
order |
a character string indicated how the observations are ordered,
i.e., |
p.adj |
a character string indicating an adjustment method for multiple
testing based on |
digits |
an integer value indicating the number of decimal places to be used for displaying results. |
p.digits |
an integer value indicating the number of decimal places to be used for displaying the p-value. |
plot |
logical: if |
geom |
character vector indicating which plot elements to draw,
i.e., |
filename |
a character string indicating the |
width |
a numeric value indicating the |
height |
a numeric value indicating the |
dpi |
a numeric value indicating the |
write |
a character string naming a text file with file extension
|
append |
logical: if |
check |
logical: if |
output |
logical: if |
... |
additional plotting arguments from the |
Returns an object of class misty.object, which is a list with following
entries:
call |
function call |
type |
type of analysis |
model |
model specified in |
plot |
ggplot2 object for plotting the results |
args |
specification of function arguments |
result |
data frame with results |
This function is based on the resettest(), harvtest(),
and raintest() function in the lmtest package by Achim Zeileis
and Torsten Hothorn.
Takuya Yanagida
Harvey, A., & Collier, P. (1977). Testing for functional misspecification in regression analysis. Journal of Econometrics, 6(1), 103-119.
Ramsey, J. B. (1969). Tests for specification errors in classical linear least-squares regression analysis. Journal of the Royal Statistical Society: Series B (Methodological), 31(2), 350-371.
Utts, J. M. (1982). The rainbow test for lack of fit in regression. Communications in Statistics - Theory and Methods, 11(24), 2801-2815.
Zeileis, A., & Hothorn, T. (2002). Diagnostic checking in regression relationships. R News, 2(3), 7-10.
check.resid, test.homo, test.norm,
coeff.robust
## Not run:
#————————————————————————————————————————————————————————————————————————————
# Tests for Linearity in a Linear Model
# Estimate linear model
mod <- lm(mpg ~ disp + hp + drat, data = mtcars)
# Example 1a: RESET test (default)
test.linear(mod)
# Example 1b: Harvey-Collier test
test.linear(mod, method = "harv")
# Example 1c: Rainbow test
test.linear(mod, method = "rain")
#————————————————————————————————————————————————————————————————————————————
# 'order' Argument
# Example 2a: Harvey-Collier test, order observations by 'hp'
test.linear(mod, method = "harv", order = "hp")
# Example 2a: Rainbow test, order by Mahalanobis distances
test.linear(mod, method = "rain", order = "mahalanobis")
#————————————————————————————————————————————————————————————————————————————
# Plot
# Example 3a: Partial residual plots
test.linear(mod, plot = TRUE)
# Example 3b: Plot with smoothing line only
test.linear(mod, plot = TRUE, geom = "loess")
# Example 3c: Partial residual plots, additional arguments
# see Details in the help page of the function plot.misty.object
test.linear(mod, plot = TRUE, point.size = 1, point.shape = 2)
# Example 3d: Plot results using the plot() function, additional arguments
# see Details in the help page of the function plot.misty.object
object <- test.linear(mod)
plot(object, point.size = 1, point.shape = 2)
#————————————————————————————————————————————————————————————————————————————
# Write Results
# Example 4a: Write results into a text file
test.linear(mod, write = "Test_Linear.txt")
# Example 4b: Write results into an Excel file
test.linear(mod, write = "Test_Linear.xlsx")
# Example 4c: Save plot as PNG file
test.linear(mod, plot = TRUE, filename = "Linear.png", width = 15, height = 5)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.