[R] contrasts in lm

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Fri Aug 31 05:48:40 CEST 2001


I've been playing around with contrasts in lm by specifying the contrasts
argument.  So, I want to specify a specific contrast to be tested

Say:

	> y _ rnorm(100)
	> x _  cut(rnorm(100, mean=y, sd=0.25),c(-3,-1.5,0,1.5,3))
	> reg _ lm(y ~ x, contrasts=list(x=c(1,0,0,-1)))
	> coef(reg)[2]
	      x1 
	-1.814101 

I was surprised to see that I get a different estimate for the contrast
specified this way than if I do

	> reg2 _ lm(y ~ x, contrasts=list(x=contr.sum))
	> coef(reg2)[2]
	       x1 
	-1.816682 

even though the first contrast in the same in both cases:

	> reg$contrasts
	$x
	          [,1]       [,2]        [,3]
	(-3,-1.5]    1 -0.2697521  0.42099143
	(-1.5,0]     0 -0.3256196 -0.80247857
	(0,1.5]      0  0.8651239 -0.03950429
	(1.5,3]     -1 -0.2697521  0.42099143
	> reg2$contrasts
	$x
	          [,1] [,2] [,3]
	(-3,-1.5]    1    0    0
	(-1.5,0]     0    1    0
	(0,1.5]      0    0    1
	(1.5,3]     -1   -1   -1

Questions:

  1) How are columns 2 and 3 of the first contrast matrix being created and
why?
 
  2) What is the proper way of doing custom contrasts?  I'm interested in a
'general' solution.

Thanks,

Greg



LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list