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

John Fox jfox at mcmaster.ca
Fri Feb 11 17:16:07 CET 2005


Dear Manuel,

Here's an example:

> x1<-rnorm(100)
> x2<-rnorm(100)
> y<-3+0.6*x1+0.3*x2 + rnorm(100,sd=.1)
> fm<-lm(y~x1+x2)
> anova(fm, lm(y~offset(0.6*x1+0.3*x2))) # Peter's solution
Analysis of Variance Table

Model 1: y ~ x1 + x2
Model 2: y ~ offset(0.6 * x1 + 0.3 * x2)
  Res.Df      RSS Df Sum of Sq      F Pr(>F)
1     97  1.00150                           
2     99  1.01732 -2  -0.01583 0.7664 0.4675
> hyp <- matrix(c(0, 1, 0,  0, 0, 1), 2, 3, byrow=TRUE)
> hyp # the hypothesis matrix
     [,1] [,2] [,3]
[1,]    0    1    0
[2,]    0    0    1
> linear.hypothesis(fm, hyp, c(0.6, 0.3))
F-Test 
SS = 0.01582501     SSE = 1.001495     F = 0.7663671  Df = 2 and 97     p =
0.4674909 
> 

My apologies for not including an example in my original response.

Regards,
 John

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Manuel 
> Gutierrez
> Sent: Friday, February 11, 2005 10:12 AM
> To: Peter Dalgaard; John Fox
> Cc: r-help at stat.math.ethz.ch; 'Vito Ricci'; 
> manuel_gutierrez_lopez at yahoo.es
> Subject: Re: [R] Re: testing slopes different than a given value
> 
> Thanks to all,
> Yes, I meant a single test for both coefficients.
> Peter's reply is what I wanted. I've tried with 
> linear.hypothesis but I must confess that with my limited 
> statistical experience and without the car book at hand, the 
> nomenclature for the function was a bit difficult to 
> understand for me. A toy example of linear.hypothesis for my 
> case would be great.


> Thanks,
> Manuel
> --- Peter Dalgaard <p.dalgaard at biostat.ku.dk>
> escribió: 
> > "John Fox" <jfox at mcmaster.ca> writes:
> > 
> > > 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
> > 
> > ...in which case one answer is this:
> > 
> > >  y<-3+0.6*x1+0.3*x2 + rnorm(100,sd=.1) # as meant,
> > no?
> > >  fm<-lm(y~x1+x2)
> > >  anova(fm, lm(y~offset(0.6*x1+0.3*x2)))
> > Analysis of Variance Table
> > 
> > Model 1: y ~ x1 + x2
> > Model 2: y ~ offset(0.6 * x1 + 0.3 * x2)
> >   Res.Df      RSS Df Sum of Sq      F Pr(>F)
> > 1     97  1.06118
> > 2     99  1.06184 -2  -0.00066 0.0302 0.9703
> > 
> > 
> > 
> > -- 
> >    O__  ---- Peter Dalgaard             Blegdamsvej
> > 3  
> >   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N 
> >  
> >  (*) \(*) -- University of Copenhagen   Denmark     
> > Ph: (+45) 35327918
> > ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)            
> > FAX: (+45) 35327907
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list