[R] Re: testing slopes different than a given value

John Fox jfox at mcmaster.ca
Fri Feb 11 14:01:50 CET 2005


Dear Vito,

Since Manuel says that he wants to "obtain a test" and not "obtain two
tests," I assume that he's interested in the F-test for the hypothesis that
both coefficients are simultaneously equal to the specified values rather
than in the t-tests for the individual hypotheses.

Regards,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Vito Ricci
> Sent: Friday, February 11, 2005 3:30 AM
> To: r-help at stat.math.ethz.ch
> Cc: manuel_gutierrez_lopez at yahoo.es
> Subject: [R] Re: testing slopes different than a given value
> 
> Hi,
> 
> We know that a regression coefficent fitted by sample data 
> (under usual linear model hypothesis) b_hat has mean=b and 
> se=se(b_hat); (b_hat-b)/s(b_hat) is distributed as Student's 
> t distribution with df=n-2.
> So you can test h0:b=b0 hA:b<>b0 using t test (for large 
> sample normal distribution is the same of a t
> distribution):
> 
> x1<-rnorm(100)
> x2<-rnorm(100)
> e<-rnorm(100)
> y<-3+0.6*x1+0.3*x2 +e
> fm<-lm(y~x1+x2)
> 
> > summary(fm)
> 
> Call:
> lm(formula = y ~ x1 + x2)
> 
> Residuals:
>      Min       1Q   Median       3Q      Max 
> -2.17610 -0.65146 -0.09532  0.54848  2.41966 
> 
> Coefficients:
>             Estimate Std. Error t value Pr(>|t|)    
> (Intercept)  3.04924    0.09661  31.562  < 2e-16 ***
> x1           0.55124    0.09930   5.551 2.47e-07 ***
> x2           0.23477    0.10534   2.229   0.0281 *  
> ---
> Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.'
> 0.1 ` ' 1 
> 
> Residual standard error: 0.9492 on 97 degrees of freedom
> Multiple R-Squared: 0.2687,     Adjusted R-squared:
> 0.2536
> F-statistic: 17.82 on 2 and 97 DF,  p-value: 2.561e-07
> > b<-coef(fm)
> > b
> (Intercept)          x1          x2 
>   3.0492374   0.5512398   0.2347682
> you get b_hat standard errors from summary(fm):
> 
> se<-c(0.09661,0.09930,0.10534)
> > se
> [1] 0.09661 0.09930 0.10534
> 
> ttest<-(b[2]-0.6)/se[2]
> 
> > ttest
>         x1
> -0.4910391
> > 1-pt(ttest,df=97) ##p-value, as df is high we can
> use normal distribution
>       x1
> 0.687746 
> 
> we accept h0 :b1=0.6;
> 
> Hoping I helped you.
> Best regards,
> Vito
> 
> You wrote:
> In a multiple linear regression with two independent 
> variables is there any function in R to test for the 
> coefficients being different than some given values?
> Example:
> x1<-rnorm(100)
> x2<-rnorm(100)
> y<-3+0.6*x1+0.3*x2
> fm<-lm(y~x1+x2)
> Obtain a test for the coefficients for x1 being different 
> than 0.6 and for x2 different than 0.3 Thanks Manuel
> 
> 
>




More information about the R-help mailing list