[R] Question about rank() function
Moshe Olshansky
m_olshansky at yahoo.com
Thu Feb 11 08:35:11 CET 2010
Hi,
I believe that the reason is that even though the first 4 elements of your fmodel look equal (when rounded to 4 decimal places) they are actually not.
To check this try
fmodel[1:4]-fmodel[1]
--- On Thu, 11/2/10, Something Something <mailinglists19 at gmail.com> wrote:
> From: Something Something <mailinglists19 at gmail.com>
> Subject: [R] Question about rank() function
> To: r-help at r-project.org
> Received: Thursday, 11 February, 2010, 6:23 PM
> Hello,
>
> I am trying to get the 'rank' function to work for me, but
> not sure what I
> am doing wrong. Please help.
>
> I ran the following commands:
>
> data = read.table("test1.csv", head=T, as.is=T,
> na.string=".", row.nam=NULL)
> X1 = as.factor(data[[3]])
> X2 = as.factor(data[[4]])
> X3 = as.factor(data[[5]])
> Y = data[[2]]
> model = lm(Y ~ X1*X2*X3, na.action = na.exclude)
> fmodel = fitted(model)
> fmodel
> (First line is shown below.....)
>
>
> 1
> 2 3
> 4 5
> 6 7
> 8
> 9 10
> 11
> 12 13
> 14
> 15 16
> 17
> 180.3763 180.3763 180.3763 180.3763 180.4546 180.3763
> 177.9245 177.9245
> 181.3859 180.3763 NA
> 180.4546 180.3763 180.4546 180.3763 180.3763
> 180.4546
>
> Then I run:
> fmodel.rank = rank(fmodel)
> fmodel.rank
> (First line is shown below....)
>
> 1 2
> 3 4
> 5 6
> 7 8
> 9 10 11
> 12
> 13 14 15 16
> 17 18 19
> 20 21 22 23
> 24 25
> 26
> 375.0 222.0 68.5 68.5 402.5 222.0
> 33.5 33.5 465.5 222.0 500.0 402.5
> 222.0 402.5 222.0 222.0 378.5 222.0 222.0 222.0 222.0 222.0
> 402.5 222.0
> 33.5 222.0
>
>
> As you can see, first 4 values of 'fmodel' are 180.3763, so
> after running
> rank(fmodel) I expected the ranks of first 4 to be the
> same, but they are
> not. What am I doing wrong? Please let me
> know. Thanks.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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