[Rd] Using response variable in interaction as explanatory variable in glm crashes R

Jan van der Laan
Fri, 06 Oct 2017 10:13:39 -0000

It is actually model.matrix that crashes, not glm. Same crash occurs
with e.g. lm.

model.matrix(dob_mon ~ dob_day*dob_mon, data = tab)

also crashes R.

Jan



On 06-10-17 12:08, Jan van der Laan wrote:
>
> The following code crashes R (I know I shouldn't try to estimate such
> a model; this was a bug in some code of mine). I also tried with
> R-devel; same result.
>
>
> tab <- structure(list(dob_day = c(FALSE, FALSE, FALSE, FALSE, TRUE,
> TRUE, TRUE, TRUE), dob_mon = c(FALSE, FALSE, TRUE, TRUE, FALSE,
> FALSE, TRUE, TRUE), dob_year = c(FALSE, TRUE, FALSE, TRUE, FALSE,
> TRUE, FALSE, TRUE), n = c(1489634L, 17491L, 134985L, 1639L, 47892L,
> 611L, 4365L, 750L), pred1 = c(1488301, 18187, 135605, 1657, 48547,
> 593, 4423, 54)), .Names = c("dob_day", "dob_mon",
"dob_year",
> "n", "pred1"), row.names = c(NA, -8L), class =
"data.frame")
>
> m <- glm(dob_mon ~ dob_day*dob_mon, data = tab, family = binomial())
>
>
> The crash doesn't when the variables are added just as main effects
> (dob_day+dob_mon): this results in a warning and the removal of
> dob_mon from the formula.
>
> --
>
> Jan
>
>
>
> > R.version
> ?????????????? _
> platform?????? x86_64-pc-linux-gnu
> arch?????????? x86_64
> os???????????? linux-gnu
> system???????? x86_64, linux-gnu
> status
> major????????? 3
> minor????????? 4.1
> year?????????? 2017
> month????????? 06
> day??????????? 30
> svn rev??????? 72865
> language?????? R
> version.string R version 3.4.1 (2017-06-30)
> nickname?????? Single Candle
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel