Hello, I am currently using brms to analyze an observational data set that records how far people walk per day. I am interested in modeling the relationship between age and distance walked per day, broken down by gender (treat gender as a factor, and fit a smooth for each gender). One feature of the data is that the age range differs for males and females: male ages span the range 3 to 68, while female ages span the range of 2-84. I have found that when I fit a model to the total dataset, using ‘by’ to request a smooth to be fit to males and females separately, and then use marginal_effects to view the posterior, I see that the estimated smooth for males extends past the observed range of male ages, and that (as can be expected) these estimates are wildly uncertain and unrealistic. This makes me wonder whether there is a way to set up the model formula such that for each level of the smooth, the smooth is only estimated across the observed range of the predictor variables within that category?
The data are also structured by repeated observations of individuals and study locations, which I model with random effects.
Here is the model formula that I am using currently
bf(distance_walked ~ gender + s(age, by=gender) + (1|person) + (1|location), shape~gender+ s(age, by=gender) + (1|person) + (1|location))
I’d be happy to provide a plot of the marginal_effects plot that is making me nervous or other information, but since my question doesn’t seem to be dependent on the features of a particular dataset I’ll post this now.
- Operating System: macOS Sierra 10.12.6
- brms Version: 2.8.0