[R] forcing a zero level in contr.sum

David Winsemius
2010-07-07T21:55:31Z

Please do not post with ambiguous questions lacking sufficient R code
and data to represent the problem.

On Jul 7, 2010, at 4:41 PM, Bond, Stephen wrote:

> Please, do not post if you do not know the answer. People will see
> this has answers and skip.

More likely people will see that it has insufficient detail to
answer ,,, and then also skip. You still have not provided any insight
into the structure of "fixw".

>
> I tried with
> mat1=contrasts(fixw$snconv)
> mat1=mat1[,-2]
> summary(frm2sum <- glm(resp.frm ~ C(snconv,contr=mat1)+mprime
> +mshape,data=fixw,family="quasibinomial"))
>
> the unwanted level is still there.

But did you try:

  summary(frm2sum <- glm(resp.frm ~ relevel(snconv, ref="03") +
mprime +
                            mshape, data=fixw,
family="quasibinomial"))

(The above obviously not tested on "fixw"  in the absence of a
reproducible example, but was an analog modulo the minimal information
offered was tested on the quasipoisson example in help page of
"family".)

--
David.

>  Unbelievable.

<snarky comment deleted>

>
> Stephen Bond
>
> -----Original Message-----
> From: David Winsemius [mailto:dwinsemius at comcast.net]
> Sent: Wednesday, July 07, 2010 4:15 PM
> To: Bond, Stephen
> Cc: r-help at r-project.org
> Subject: Re: [R] forcing a zero level in contr.sum
>
>
> On Jul 7, 2010, at 4:04 PM, Bond, Stephen wrote:
>
>> Clarifying my question:
>>
>> options(contrasts = c("contr.sum", "contr.poly"))
>>> contrasts()
>>  [,1] [,2] [,3] [,4] [,5]
>> 01    1    0    0    0    0
>> 03    0    1    0    0    0
>> 05    0    0    1    0    0
>> 06    0    0    0    1    0
>> 07    0    0    0    0    1
>> 09   -1   -1   -1   -1   -1
>>
>> I need to force the coefficient on level 03 to be zero.
>
> ?factor
> ?relevel
>
>
> Perhaps worth a try:
>
> fixw$snconv <- relevel(fixw$snconv, ref="03")
>
>
> (But I wonder if using contr.sum will ever generally satisfy that
> goal, since contr.sum calculates the difference from a grand mean and
> this will only work if a) the GM=0 and b) there is only one term on
> the RHS of the model, and c) probably a bunch of other restrictions.)
>
> --
> David.
>>
>> Thank you.
>>
>> Stephen Bond
>> -----Original Message-----
>> From: David Winsemius [mailto:dwinsemius at comcast.net]
>> Sent: Wednesday, July 07, 2010 3:44 PM
>> To: Bond, Stephen
>> Cc: r-help at r-project.org
>> Subject: Re: [R] forcing a zero level in contr.sum
>>
>>
>> On Jul 7, 2010, at 3:13 PM, Bond, Stephen wrote:
>>
>>> I need to use contr.sum and observe that some levels are not
>>> statistically different from the overall mean of zero.
>>> What is the proper way of forcing the zero estimate? It seems the
>>> column corresponding to that level should become a column of zeros.
>>> Is there a way to achieve that without me constructing the design
>>> matrix?
>>> Thank you.
>>
>> lm( formula = z ~ x + y + 0,   ...)  _might_ do something close to
>> what you want.
>>
>>
>>
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.