fix for issue with link not adding intercept for linear models#285
fix for issue with link not adding intercept for linear models#285mattelisi wants to merge 1 commit intormcelreath:masterfrom
Conversation
….character in line 55 to deparse)
|
The issue here is that the model doesn't have a linear model. The version of m4.3 in the main text includes an explicit linear model, and I believe that works, yes? |
|
Ah! Yes indeed, I just tried and it works. I think the issue is then that map() returns correct results regardless of whether the linear formula is inside or outside of dnorm(), no errors or warnings are returned, but then link() gives different results depending on whether the linear formula is inside or outside the density. The documentation of map does not explicitly warn against putting the linear formula within the density function, so some of our students put it inside and we were unsure about why they were getting correct estimates of parameters but wrong predictions. Switching to deparse, or adding c() in the part that extract the model formula seems to give correct results regardless of whether the linear formula is inside or outside the density. |
|
Okay, thanks. I will think about whether link() on a model without an explicit linear model should fail loudly. Or I could fix it, using your approach, but I'd need some new tests. Your note about using c() makes it clear what is happening, I think. So thanks! |
|
I pulled this manually into the experimental branch. 3941b14 I still need to run all the test before I merge into master. And I need some new tests for this specific issue now. But I think it works. |
Related pull request fix for issue with link not adding intercept for linear models rmcelreath#285 I'm having trouble using sim with models that have index variables. Some debug code is crashing, and I think this may fix it.
We found that there was an issue with the
link()function not returning the correct predictions. For example:Note that link give the predictions that are far from the actual values of heights (136+)
I tracked this down to the use of
as.characterto get formula of the modelI think this is related to the formula being a language type of object. I read in the help that
deparse, which is normally preferable to as.character for language objects. Indeed usingdeparse:After loading the updated version (
devtools::install_github("mattelisi/rethinking", ref="test-link-issues")) the numbers are correctAn alternative approach that seems to work is
as.character( c( m4.3@formula[[1]][[3]][[2]] )).