rstanarm
rstanarm copied to clipboard
stan_gamm4: bug with polynomial parameter
rstanarm appears to fail when entering a polynomial parameter:
This works
rstanarm::stan_gamm4(Sepal.Width ~ Sepal.Length + s(Petal.Width), random=~(1|Species), data=iris)
This doesn't
rstanarm::stan_gamm4(Sepal.Width ~ poly(Sepal.Length, 2) + s(Petal.Width), random=~(1|Species), data=iris)
Error in poly(Sepal.Length, 2) : object 'Sepal.Length' not found
Note that the same using gamm4 works:
gamm4::gamm4(Sepal.Width ~ poly(Sepal.Length, 2) + s(Petal.Width), random=~(1|Species), data=iris)
Is there a way to fix it?
We'll look into it, but
Sepal.Width ~ Sepal.Length + I(Sepal.Length^2) + s(Petal.Width), random = ~(1 | Species), data = iris)
should at least get it going.
On Tue, Jul 24, 2018 at 6:48 AM Dominique Makowski [email protected] wrote:
rstanarm appears to fail when entering a polynomial parameter: This works
rstanarm::stan_gamm4(Sepal.Width ~ Sepal.Length + s(Petal.Width), random=~(1|Species), data=iris)
This doesn't
rstanarm::stan_gamm4(Sepal.Width ~ poly(Sepal.Length, 2) + s(Petal.Width), random=~(1|Species), data=iris)
Error in poly(Sepal.Length, 2) : object 'Sepal.Length' not found
Note that the same using gamm4 works:
gamm4::gamm4(Sepal.Width ~ poly(Sepal.Length, 2) + s(Petal.Width), random=~(1|Species), data=iris)
Is there a way to fix it?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/305, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqs4kVYB0shWDELLkoVcHdGsL0mLwks5uJvtpgaJpZM4Vcgk1 .
@bgoodri Thanks, the workaround works (although I am wondering if it's possible to set orthogonal polynomials this way).
With QR = TRUE
On Mon, Oct 8, 2018 at 1:16 PM Dominique Makowski [email protected] wrote:
@bgoodri https://github.com/bgoodri Thanks, the workaround works (although I am wondering if it's possible to set orthogonal polynomials this way).
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/305#issuecomment-427912997, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqn2c6u8mBz59dFseDVNRkmzzRvuoks5ui4iFgaJpZM4Vcgk1 .
It seems that setting QR to TRUE does not change raw polynomials to orthogonal polynomials:
GAMM4 - Orthogonal
gamm4::gamm4(Sepal.Width ~ poly(Sepal.Length, 2) + s(Petal.Width), random=~(1|Species), data=iris)
The fixed coefs are roughly 3.26 and -1.2.
GAMM4 - Raw
gamm4::gamm4(Sepal.Width ~ Sepal.Length + I(Sepal.Length^2) + s(Petal.Width), random=~(1|Species), data=iris)
The fixed coefs are roughly 1.8 and -0.1.
rstanarm - QR FALSE
rstanarm::stan_gamm4(Sepal.Width ~ Sepal.Length + I(Sepal.Length^2) + s(Petal.Width), random=~(1|Species), data=iris)
The fixed coefs are roughly 1.7 and -0.1.
rstanarm - QR TRUE
rstanarm::stan_gamm4(Sepal.Width ~ Sepal.Length + I(Sepal.Length^2) + s(Petal.Width), random=~(1|Species), data=iris, QR=TRUE)
The fixed coefs are roughly the same as just above.
The parameters are estimated under an orthogonal rotation (the Q matrix from the X=QR decomposition) and then after the initial posterior distribution has been obtained the coefficients are re-rotated back to the original coordinates so that they pertain to the columns of X. So, you get the efficiency benefits of orthogonalization without changing the interpretation of the output.
On Tue, Oct 9, 2018 at 3:42 AM Dominique Makowski [email protected] wrote:
It seems that setting QR to TRUE does not change raw polynomials to orthogonal polynomials: GAMM4 - Orthogonal
gamm4::gamm4(Sepal.Width ~ poly(Sepal.Length, 2) + s(Petal.Width), random=~(1|Species), data=iris)
The fixed coefs are roughly 3.26 and -1.2. GAMM4 - Raw
gamm4::gamm4(Sepal.Width ~ Sepal.Length + I(Sepal.Length^2) + s(Petal.Width), random=~(1|Species), data=iris)
The fixed coefs are roughly 1.8 and -0.1. rstanarm - QR FALSE
rstanarm::stan_gamm4(Sepal.Width ~ Sepal.Length + I(Sepal.Length^2) + s(Petal.Width), random=~(1|Species), data=iris)
The fixed coefs are roughly 1.7 and -0.1. rstanarm - QR TRUE
rstanarm::stan_gamm4(Sepal.Width ~ Sepal.Length + I(Sepal.Length^2) + s(Petal.Width), random=~(1|Species), data=iris, QR=TRUE)
The fixed coefs are roughly the same as just above.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/305#issuecomment-428093007, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqgC62WIyQRI7VeBGitQ74-50TNdkks5ujFNngaJpZM4Vcgk1 .
Thanks for the clarification! (Although in my case I needed the interpretation of orthogonal polynomials ☺️, but I managed to compute them beforehand and feed them directly in the model.)