What package in R is used to calculate non-zero null hypothesis p-values on linear models?

a 夏天 提交于 2021-02-17 06:17:06

问题


The standard summary(lm(Height~Weight)) will output results for the hypothesis test H0: Beta1=0, but if I am interested in testing the hypothesis H0: B1=1 is there a package that will produce that p-value? I know I can calculate it by hand and I know I can "flip the confidence interval" for a two tailed test (test a 95% hypothesis by seeing if the 95% confint contains the point of interest), but I am looking for an easy way to generate the p-values for a simulation study.


回答1:


You can use linearHypothesis from the package car, for example:

library(car)
fit = lm(Petal.Width ~ Petal.Length,data=iris)

fit

Call:
lm(formula = Petal.Width ~ Petal.Length, data = iris)

Coefficients:
 (Intercept)  Petal.Length  
     -0.3631        0.4158  

linearHypothesis(fit,"Petal.Length=0.4")
Linear hypothesis test

Hypothesis:
Petal.Length = 0.4

Model 1: restricted model
Model 2: Petal.Width ~ Petal.Length

  Res.Df    RSS Df Sum of Sq      F Pr(>F)
1    149 6.4254                           
2    148 6.3101  1   0.11526 2.7034 0.1023

There's also an article about the specifics of this package.




回答2:


I don't know about a package that will do this, but you can test this hypothesis by using an offset:

## specify null-model parameters
null_int <- 0; null_slope <- 1
## base model
m0 <- lm(mpg ~ disp, data=mtcars)
## include offset as null model
m1 <- update(m0, . ~ . + offset(null_int + null_slope*disp))

Comparing results:

cbind(base=coef(m0),offset=coef(m1))
                  base    offset
(Intercept) 29.59985476 29.599855
disp        -0.04121512 -1.041215

You can see that the estimated slope is now 1 unit lower (since it's relative to a null model with slope=1). The summary values, standard errors, p-values etc., will all be adjusted appropriately.



来源:https://stackoverflow.com/questions/65044702/what-package-in-r-is-used-to-calculate-non-zero-null-hypothesis-p-values-on-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!