From whit at twinfieldscapital.com  Tue Sep 13 21:55:22 2005
From: whit at twinfieldscapital.com (Whit Armstrong)
Date: Tue, 13 Sep 2005 15:55:22 -0400
Subject: [Rd] possible bug in model.matrix
Message-ID: <726FC6DD09DE1046AF81B499D70C3BCE2C8623@twinfields02.CORP.TWINFIELDSCAPITAL.COM>

Is this a bug, or have I misunderstood the proper use of lm?

Thanks,
Whit


code:
x <- rnorm(50)
y <- matrix(as.logical(round(runif(100),0)),ncol=2)
NROW(x)==NROW(y)
lm(x~y)



> x <- rnorm(50)
> y <- matrix(as.logical(round(runif(100),0)),ncol=2)
> NROW(x)==NROW(y)
[1] TRUE
> lm(x~y)
Error in "[[<-.data.frame"(`*tmp*`, nn, value = c(2, 1, 2, 1, 1, 1, 2,
:
        replacement has 100 rows, data has 50
>


However, the call to lm works if the matrix is a numeric instead of
logical:
x <- rnorm(50)
y <- matrix(runif(100),ncol=2)
NROW(x)==NROW(y)
lm(x~y)


Seems to be a problem in model.matrix.default:

debug: for (nn in namD[isF]) if (is.null(attr(data[[nn]], "contrasts")))
contrasts(data[[nn]]) <- contr.funs[1 +
    isOF[nn]]
Browse[1]>
Error in "[[<-.data.frame"(`*tmp*`, nn, value = c(1, 2, 2, 2, 2, 2, 2,
:
        replacement has 100 rows, data has 50
>


> R.Version()
$platform
[1] "i686-pc-linux-gnu"

$arch
[1] "i686"

$os
[1] "linux-gnu"

$system
[1] "i686, linux-gnu"

$status
[1] "alpha"

$major
[1] "2"

$minor
[1] "2.0"

$year
[1] "2005"

$month
[1] "09"

$day
[1] "12"

$"svn rev"
[1] "35558"

$language
[1] "R"

>



[Rd] possible bug in model.matrix
Whit Armstrong