# [R] Contrasts for a data

Bert Gunter gunter.berton at gene.com
Fri Feb 8 23:20:21 CET 2013

```Rail is an ordered factor. ?ordered for details.
Default contrasts for an ordered factor are orthogonal polynomials.

See:   https://stat.ethz.ch/pipermail/r-help/2007-January/123268.html

and

http://www.ats.ucla.edu/stat/r/library/contrast_coding.htm#ORTHOGONAL

-- Bert

On Fri, Feb 8, 2013 at 1:36 PM, jing tang <gimmytang at gmail.com> wrote:
> Hi,
> I am using a data called Rail in the nlme package. The data contains two
> variables: Rail and Travel.
>>Rail
> Grouped Data: travel ~ 1 | Rail
>    Rail travel
> 1     1     55
> 2     1     53
> 3     1     54
> 4     2     26
> 5     2     37
> 6     2     32
> 7     3     78
> 8     3     91
> 9     3     85
> 10    4     92
> 11    4    100
> 12    4     96
> 13    5     49
> 14    5     51
> 15    5     50
> 16    6     80
> 17    6     85
> 18    6     83
>>Rail\$Rail
>>[1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6
>>Levels: 2 < 5 < 1 < 6 < 3 < 4
>
> Then I used the contrasts function as:
>>contrasts(Rail\$Rail)
> And it returns with some strange continuous values:
>              .L         .Q         .C         ^4          ^5
> [1,] -0.5976143  0.5455447 -0.3726780  0.1889822 -0.06299408
> [2,] -0.3585686 -0.1091089  0.5217492 -0.5669467  0.31497039
> [3,] -0.1195229 -0.4364358  0.2981424  0.3779645 -0.62994079
> [4,]  0.1195229 -0.4364358 -0.2981424  0.3779645  0.62994079
> [5,]  0.3585686 -0.1091089 -0.5217492 -0.5669467 -0.31497039
> [6,]  0.5976143  0.5455447  0.3726780  0.1889822  0.06299408
>
> I am expecting to see 0s and 1s in the contrast, but it may be due to the
> order of the factor levels for Rail variable?
>
> Best,
> Jing
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.

--

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website: