[Rd] possible bug in model.matrix

Whit Armstrong whit at twinfieldscapital.com
Tue Sep 13 21:55:22 CEST 2005


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"

>



More information about the R-devel mailing list