T-test for the difference in 2 regression parameters
waldt.RdThis is the one the students call the "fancy t test". It is just
the simplest, most easy to use version of the t test to decide if
2 coefficients are equal. It is not as general as other functions
in other packages. This is simpler to use for beginners. The
car package's function linearHypothesis is more
general, but its documentation is much more difficult to understand.
It gives statistically identical results, albeit phrased as an F
test.
Usage
waldt(parm1, parm2, model, model.cov = NULL, digits = getOption("digits"))Arguments
- parm1
A parameter name, in quotes!
- parm2
Another parameter name, in quotes!
- model
A fitted regression model
- model.cov
Optional, another covariance matrix to use while calculating the test. Primarily used for robust (or otherwise adjusted) standard errors
- digits
How many digits to print? This affects only the on-screen printout. The return object is numeric, full precision.
Value
A vector with the difference, std. err., t-stat, and p value. Prints a formatted output statement.
Details
I did this because we have trouble understanding terminology in documentation for more abstract functions in other R packages.
It has an additional feature, it can import robust standard errors to conduct the test.
Author
Paul Johnson pauljohn@ku.edu
Examples
mdat <- data.frame(x1 = rnorm(100), x2 = rnorm(100))
stde <- 2
mdat$y <- 0.2 * mdat$x1 + 0.24 * mdat$x2 + stde * rnorm(100)
m1 <- lm(y ~ x1 + x2, data = mdat)
waldt("x1", "x2", m1)
#> diff Std.Err. t p
#> "0.1579907" "0.3334825" "0.4737601" "0.6367356"
waldt("x1", "x2", m1, digits = 2)
#> diff Std.Err. t p
#> "0.16" "0.33" "0.47" "0.64"
## Returned object is not "rounded characters". It is still numbers
stillnumeric <- waldt("x1", "x2", m1, digits = 2)
#> diff Std.Err. t p
#> "0.16" "0.33" "0.47" "0.64"
stillnumeric
#> diff Std.Err. t p
#> 0.1579907 0.3334825 0.4737601 0.6367356
## Equivalent to car package linearHypothesis:
if(require(car)){
linearHypothesis(m1, "x1 = x2")
}
#> Loading required package: car
#> Warning: there is no package called ‘car’
## recall t = sqrt(F) for a 1 degree of freedom test.
## If we could understand instructions for car, we probably
## would not need this function, actually.