[R] quadratic trends and changes in slopes (R-help digest, Vol 1 #52 - 16 msgs)

Chuck White chuck at chuckandmaggi.com
Mon Jan 20 16:35:02 CET 2003


-----Original Message-----
 Message: 6
Date: Mon, 20 Jan 2003 01:11:24 +0100
From: Martin Michlmayr <tbm at cyrius.com>
To: r-help at stat.math.ethz.ch
Subject: [R] quadratic trends and changes in slopes

I'd like to use linear and quadratic trend analysis in order to find
out a change in slope.  Basically, I need to solve a similar problem as
discussed in
http://www.gseis.ucla.edu/courses/ed230bc1/cnotes4/trend1.html

....

RESPONSE: Since I'm in the process of switching from SAS to R, this was
a good exercise for me. An R program to work the example you cited is
appended. I hope this meets your needs.

Chuck White

# R program for working example at:
# http://www.gseis.ucla.edu/courses/ed230bc1/cnotes4/trend2.html
#
# Copy and paste the example data from the web to a plain text editor
# and save as 'example.txt'. Read the data as follows:

example<-read.table("example.txt", header = FALSE, 
col.names=c('y','grp','o1','o2','o3'))
example

# Make variable names available to session

attach(example)

# Convert grp from numeric format to factor format for ANOVA

fgrp<-factor(grp)
fgrp

# Conduct ANOVA on grp

GRP<-lm(y~fgrp)
anova(GRP)

# Conduct ANOVA on contrasts

Contrasts<-lm(y~o1+o2+o3)
anova(Contrasts)

# I'm sure that an R veteran would have some slick way to do the
'Nonlinear'
# contrast but I used a pocket calculator to verify that the sum of
squares 
# for quadratic plus the sum of squares for cubic divided by 2 degrees
of 
# freedom and divided again by mean square error did indeed equal 3.28.
I 
# then obtained the p-value for 2,28 degrees of freedom as follows:

1-pf(3.28,2,28)




More information about the R-help mailing list