View source: R/goldfeld_quandt.R
goldfeld_quandt | R Documentation |
This function implements the two methods (parametric and nonparametric) of \insertCiteGoldfeld65;textualskedastic for testing for heteroskedasticity in a linear regression model.
goldfeld_quandt( mainlm, method = c("parametric", "nonparametric"), deflator = NA, prop_central = 1/3, group1prop = 1/2, alternative = c("greater", "less", "two.sided"), prob = NA, twosidedmethod = c("doubled", "kulinskaya"), restype = c("ols", "blus"), statonly = FALSE, ... )
mainlm |
Either an object of |
method |
A character indicating which of the two tests derived in \insertCiteGoldfeld65;textualskedastic should be implemented. Possible values are "parametric" and "nonparametric". Default is "parametric". It is acceptable to specify only the first letter. |
deflator |
Either a character specifying a column name from the
design matrix of |
prop_central |
A double specifying the proportion of central
observations to exclude from the F test (when |
group1prop |
A double specifying the proportion of remaining
observations (after excluding central observations) to allocate
to the first group. The default value of |
alternative |
A character specifying the form of alternative
hypothesis. If it is suspected that the
error variance is positively associated with the deflator variable,
|
prob |
A vector of probabilities corresponding to values of the test
statistic (number of peaks) from 0 to n-1 inclusive (used
only when |
twosidedmethod |
A character indicating the method to be used to compute
two-sided p-values for the parametric test when |
restype |
A character specifying which residuals to use: |
statonly |
A logical. If |
... |
Optional further arguments to pass to |
The parametric test entails putting the data rows in increasing order of some specified deflator (one of the explanatory variables). A specified proportion of the most central observations (under this ordering) is removed, leaving a subset of lower observations and a subset of upper observations. Separate OLS regressions are fit to these two subsets of observations (using all variables from the original model). The test statistic is the ratio of the sum of squared residuals from the 'upper' model to the sum of squared residuals from the 'lower' model. Under the null hypothesis, the test statistic is exactly F-distributed with numerator and denominator degrees of freedom equal to (n-c)/2 - p where n is the number of observations in the original regression model, c is the number of central observations removed, and p is the number of columns in the design matrix (number of parameters to be estimated, including intercept).
The nonparametric test entails putting the residuals of the linear model in increasing order of some specified deflator (one of the explanatory variables). The test statistic is the number of peaks, with the jth absolute residual |e_j| defined as a peak if |e_j|≥|e_i| for all i<j. The first observation does not constitute a peak. If the number of peaks is large relative to the distribution of peaks under the null hypothesis, this constitutes evidence for heteroskedasticity.
An object of class
"htest"
. If object is
not assigned, its attributes are displayed in the console as a
tibble
using tidy
.
lmtest::gqtest
, another implementation
of the Goldfeld-Quandt Test (parametric method only).
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars) goldfeld_quandt(mtcars_lm, deflator = "qsec", prop_central = 0.25) # This is equivalent to lmtest::gqtest(mtcars_lm, fraction = 0.25, order.by = mtcars$qsec) goldfeld_quandt(mtcars_lm, deflator = "qsec", method = "nonparametric", restype = "blus") goldfeld_quandt(mtcars_lm, deflator = "qsec", prop_central = 0.25, alternative = "two.sided") goldfeld_quandt(mtcars_lm, deflator = "qsec", method = "nonparametric", restype = "blus", alternative = "two.sided")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.