[R-sig-ME] glmmTMB- fitting splines
dani
orchidn @ending from live@com
Tue May 22 02:13:12 CEST 2018
Hello Dr Bolker,
Thank you so much for your prompt and helpful answer! This is great!
Best regards,
Dani
Sent from Outlook<http://aka.ms/weboutlook>
________________________________
From: R-sig-mixed-models <r-sig-mixed-models-bounces at r-project.org> on behalf of Ben Bolker <bbolker at gmail.com>
Sent: Monday, May 21, 2018 5:09 PM
To: r-sig-mixed-models at r-project.org
Subject: Re: [R-sig-ME] glmmTMB- fitting splines
I don't know of an example offhand, but
https://stats.stackexchange.com/questions/301666/using-splines-in-r-lme4glmer-scale-issues
gives an example of using splines::ns(). Basically, you can use ns()
as a drop-in term within a formula; unlike the magical s() function in
mgcv, you have to specify the number of knots/degrees of freedom
yourself (splines::ns fits regression splines, mgcv::s fits *penalized*
regression splines).
Perhaps not known to everyone, mgcv can handle some forms of
zero-inflation (although I think it does ZIP but not ZINB), so
https://www.fromthebottomoftheheap.net/2017/05/04/compare-mgcv-with-glmmTMB/
might also be useful.
Here's an example. It is in principle possible to use
(ns(Days,5)|Subject) as the random effect (i.e. let curves vary among
individuals), but it didn't work in this case -- too complex for this
medium-size data set.
library(glmmTMB)
data(sleepstudy,package="lme4")
library(splines)
m1 <- glmmTMB(Reaction~ns(Days,5)+(1|Subject), data=sleepstudy)
sleepstudy$pred <- predict(m1)
library(ggplot2)
ggplot(sleepstudy,aes(x=Days))+geom_point(aes(y=Reaction))+geom_line(aes(y=pred,group=Subject))
On 2018-05-21 07:36 PM, dani wrote:
> Hello everyone,
>
>
> I am working with a glmmTMB model with two random effects. Some of my
> covariates have non-parametric associations with my dependent
> variable so I would like to fit splines for them. I am not sure how
> my code should look like.
>
>
> Could someone point me towards an example using glmmTMB with splines?
> I am not really sure how to interpret such a model.
>
>
> Thanks!
>
> Best regards,
>
> Dani
>
>
>
> <http://aka.ms/weboutlook>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list