[R] Setting the desired reference category with contr.sum

Ista Zahn istazahn at gmail.com
Fri Oct 5 15:31:51 CEST 2012


Hi,

The contr. functions return matrices, so you can can create any
arbitrary matrix you like. For example

contrasts(career) <- cbind(c1=c(-1, 1, 0, 0, 0, 0),
                                      c2=c(-1, 0, 1, 0, 0, 0),
                                      c3=c(-1, 0, 0, 1, 0, 0),
                                      c4=c(-1, 0, 0, 0, 1, 0),
                                      c5=c(-1, 0, 0, 0, 0, 1))

Best,
Ista

On Fri, Oct 5, 2012 at 8:01 AM, autarkie <kovla123 at hotmail.com> wrote:
> Hi,
>
> I have 6 career types, represented as a factor in R, coded from 1 to 6. I
> need to use the effect coding (also known as deviation coding) which is
> normally done by contr.sum, e.g.
>
> contrasts(career) <- contr.sum(6)
>
> However, this results in the 6th category being the reference, that is being
> coded as -1:
>
> $contrasts
>   [,1] [,2] [,3] [,4] [,5]
> 1    1    0    0    0    0
> 2    0    1    0    0    0
> 3    0    0    1    0    0
> 4    0    0    0    1    0
> 5    0    0    0    0    1
> 6   -1   -1   -1   -1   -1
>
> In fact, I need number 1 to be the reference. How do I achieve that? Thank
> you.
>
> Regards,
> Maxim
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Setting-the-desired-reference-category-with-contr-sum-tp4645150.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.




More information about the R-help mailing list