Re: [R] Contr.sum and coefficient tests

2015-07-23 Thread Ben Bolker
François Collin  nottingham.ac.uk> writes:

> 
> Dear all,
 
> I would like to run a linear model which includes two factors:

> - The first one has two levels, including a reference level. Thus I
> have to use the treatment contrast (contr.treatment, reference level
> effect = 0, then the intercept).

> - The second is a 6-level factor without reference contrast nor
> order. So, I would like to use sum contrat: sum of the effects = 0.

> The problem arises when it comes to the coefficient test. I
> understand it is not relevant to test the reference level for the
> first factor as the reference level is set to 0. However, using sum
> contrast for the second factor, I would have expected the test of
> each level to be included in the classical summary print of the lm
> function result but it is not. And here is my problem, how can I
> have every coefficients tested and printed in the summary output
> when my factor is studied from this sum.contrast standpoint?

  [some context snipped to make gmane happy -- sorry ]

  I think you should look at the effects package or the lsmeans
package (or possibly the multcomp package, if you want to be careful
about the number of (non-orthogonal) tests) -- the issue is that
summary.lm always reports on the *parameters* estimated.  If some
parameters are not independently estimable (e.g. the effect corresponding
to the last level can be reconstructed from the parameter values
for all of the preceding levels), then summary.lm() won't give
them to you.

  In fact, these packages will (probably) give you the results you
want even if the original model uses default treatment contrasts.
__
R-help@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.

[R] Contr.sum and coefficient tests

2015-07-23 Thread François Collin
Dear all,

I would like to run a linear model which includes two factors:
- The first one has two levels, including a reference level. Thus I have to use 
the treatment contrast (contr.treatment, reference level effect = 0, then the 
intercept).
- The second is a 6-level factor without reference contrast nor order. So, I 
would like to use sum contrat: sum of the effects = 0.

The problem arises when it comes to the coefficient test. I understand it is 
not relevant to test the reference level for the first factor as the reference 
level is set to 0. However, using sum contrast for the second factor, I would 
have expected the test of each level to be included in the classical summary 
print of the lm function result but it is not. And here is my problem, how can 
I have every coefficients tested and printed in the summary output when my 
factor is studied from this sum.contrast standpoint?


Here is an example from a previous thread:
(http://comments.gmane.org/gmane.comp.lang.r.general/258886)

==
> x <- as.factor(c(1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3))
> y <- c(1.1,1.15,1.2,1.1,1.1,1.1,1.2,1.2,1.2,2.1,2.2,2.3,2.4,2.5,
> +  2.6,2.7,2.8,2.9,3,3.1)
> test <- data.frame(x,y)
> reg1 <- lm(y~C(x,contr.sum),data=test)
> summary(reg1)

Coefficients:
 Estimate Std. Error t value Pr(>|t|)   
(Intercept)   1.60.06577  24.834 8.48e-15 ***
C(x, contr.sum)1 -0.483330.10792  -4.479  0.00033 ***
C(x, contr.sum)2 -0.483330.08936  -5.409 4.70e-05 ***
==

How can I include the third factor level in this table?

I fill the answer provided in this previous thread is relevant for 
contr.treatment but not for contr.sum. Am I right? Or can you explain me?

Many thanks,
Fanch



This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

__
R-help@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.