[R] F-test where the coefficients in the H_0 is nonzero
peter dalgaard
pd@|gd @end|ng |rom gm@||@com
Thu Aug 9 11:45:58 CEST 2018
The null hypothesis is different (and the different numerator Df is the givaway).
> lm0 <- lm(y~-1, df1)
> anova(lm0,lm1)
Analysis of Variance Table
Model 1: y ~ -1
Model 2: y ~ x
Res.Df RSS Df Sum of Sq F Pr(>F)
1 3 149.0
2 1 1.5 2 147.5 49.167 0.1003
-pd
> On 9 Aug 2018, at 10:58 , John <miaojpm using gmail.com> wrote:
>
> Hi,
>
> I try to run the same f-test by lm (with summary) and the function
> "linearHypothesis" in car package. Why are the results (p-values for the
> f-test) different?
>
>
>> df1<-data.frame(x=c(2,3,4), y=c(7,6,8))
>> lm1<-lm(y~x, df1)
>> lm1
>
> Call:
> lm(formula = y ~ x, data = df1)
>
> Coefficients:
> (Intercept) x
> 5.5 0.5
>
>> summary(lm1)
>
> Call:
> lm(formula = y ~ x, data = df1)
>
> Residuals:
> 1 2 3
> 0.5 -1.0 0.5
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 5.500 2.693 2.043 0.290
> x 0.500 0.866 0.577 0.667
>
> Residual standard error: 1.225 on 1 degrees of freedom
> Multiple R-squared: 0.25, Adjusted R-squared: -0.5
> F-statistic: 0.3333 on 1 and 1 DF, p-value: 0.6667
>
>> linearHypothesis(lm1, c("(Intercept)=0", "x=0"))
> Linear hypothesis test
>
> Hypothesis:
> (Intercept) = 0
> x = 0
>
> Model 1: restricted model
> Model 2: y ~ x
>
> Res.Df RSS Df Sum of Sq F Pr(>F)
> 1 3 149.0
> 2 1 1.5 2 147.5 49.167 0.1003
>
> 2018-08-03 13:54 GMT+08:00 Annaert Jan <jan.annaert using uantwerpen.be>:
>
>> You can easily test linear restrictions using the function
>> linearHypothesis() from the car package.
>> There are several ways to set up the null hypothesis, but a
>> straightforward one here is:
>>
>>> library(car)
>>> x <- rnorm(10)
>>> y <- x+rnorm(10)
>>> linearHypothesis(lm(y~x), c("(Intercept)=0", "x=1"))
>> Linear hypothesis test
>>
>> Hypothesis:
>> (Intercept) = 0
>> x = 1
>>
>> Model 1: restricted model
>> Model 2: y ~ x
>>
>> Res.Df RSS Df Sum of Sq F Pr(>F)
>> 1 10 10.6218
>> 2 8 9.0001 2 1.6217 0.7207 0.5155
>>
>>
>> Jan
>>
>> From: R-help <r-help-bounces using r-project.org> on behalf of John <
>> miaojpm using gmail.com>
>> Date: Thursday, 2 August 2018 at 10:44
>> To: r-help <r-help using r-project.org>
>> Subject: [R] F-test where the coefficients in the H_0 is nonzero
>>
>> Hi,
>>
>> I try to run the regression
>> y = beta_0 + beta_1 x
>> and test H_0: (beta_0, beta_1) =(0,1) against H_1: H_0 is false
>> I believe I can run the regression
>> (y-x) = beta_0 +beta_1‘ x
>> and do the regular F-test (using lm functio) where the hypothesized
>> coefficients are all zero.
>>
>> Is there any function in R that deal with the case where the
>> coefficients are nonzero?
>>
>> John
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> mailto:R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
More information about the R-help
mailing list