Broom.mixed exp 模型预测
我想请求一些帮助来绘制我的模型的预测值以及 lmer() 估计生成的方程。
所以,我得到的数据是不同老鼠在不同日期的质量体积。每只老鼠都有不同的时间点来测量该体积。
因此,我使用的模型是:
m1 <- lmer(lVolume ~ Country*Day + (1|Rat))
我这样做是因为我对 exp(fitted) 值感兴趣,然后获得该模型的指数方法,而不是使用非线性混合效应模型(对于 在
为了绘制该模型的预测,我的尝试是:
m1%>%
augment() %>%
clean_names() %>%
ggplot(data = .,
mapping = aes(x = day,
y = exp(l_volume),
group = rat)) +
geom_point(alpha = 0.5) +
geom_line(alpha = 0.5) +
geom_point(aes(y = exp(fitted)),
color = "red") +
geom_line(aes(y = exp(fitted)),
color = "red") +
expand_limits(x = 0 , y = 0)
这里,我绘制了更多的老鼠,但是,正如您所看到的,(0,0) 与 lmer 的预测相差太远。我想知道如何绘制模型生成的预测以查看 (0,200) 中的点。我尝试从这里创建一个新的数据框,然后再次使用预测(m1,newdata = new_df)进行绘图,但我不知道如何创建这个数据框,因为我有20只老鼠,而且我不知道如何扩展它到预测()。
我的尝试:
pframe <- data.frame(Day=seq(0, 200, length.out=101))
pframe$continuous_outcome <- predict(m1, newdata = pframe, level = 0)
ggplot(data, aes(Day,lVolume)) +
geom_point() +
geom_line(data=pframe)
但出现错误:
eval(predvars, data, env) 中的错误:未找到对象“Rat”
并且,还有一种方法可以绘制根据每个估计生成的方程,即,从每只大鼠中,您有一组固定和随机的估计器,我如何绘制 lmer 为每只老鼠生成的方程(红色曲线)?
I would like to ask for some help with plotting prediction values from my model as well as the equations generated by the estimation of the lmer().
So, the data that I have is the mass volume of different rats across different days. Each rat has different time points where they took the measurement of that volume.
So, then the model that I use is :
m1 <- lmer(lVolume ~ Country*Day + (1|Rat))
I do this because I am interested in exp(fitted)
values and then obtaining an exponential approach for this model instead of using a nonlinear mixed effect model (for the moment)
To plot the predictions from this model, my attempt was:
m1%>%
augment() %>%
clean_names() %>%
ggplot(data = .,
mapping = aes(x = day,
y = exp(l_volume),
group = rat)) +
geom_point(alpha = 0.5) +
geom_line(alpha = 0.5) +
geom_point(aes(y = exp(fitted)),
color = "red") +
geom_line(aes(y = exp(fitted)),
color = "red") +
expand_limits(x = 0 , y = 0)
Here I plotted more rats but, as you can see the (0,0) is too far from the predictions of the lmer. I was wondering how I plot the prediction that my model is generating to see points from (0,200). I tried a hint from here by creating a new data frame and then plot using again predict(m1, newdata = new_df), but I am clueless how to create this data frame since I have 20 rats and I do not know how to expand this to the predict().
My attempt:
pframe <- data.frame(Day=seq(0, 200, length.out=101))
pframe$continuous_outcome <- predict(m1, newdata = pframe, level = 0)
ggplot(data, aes(Day,lVolume)) +
geom_point() +
geom_line(data=pframe)
but I got an error:
Error in eval(predvars, data, env) : object 'Rat' not found
And, also is there a way to plot also the equations that you generate from each estimation, i.e, from each rat you have a set of estimators fixed and random, how can I plot the equation (red curves) that the lmer is generating for each of the rats?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,使用
predict
比使用broom.mixed::augment
更容易。构建预测
(老鼠/国家/天数 0-150 的所有组合(天数达到 200 会导致一些极端的预测,超出垂直范围)
将数据和预测合并到一个数据框中(您不必这样做,但它使图例变得简单)
情节:
重建数据:
It turned out to be easier to use
predict
thanbroom.mixed::augment
.construct predictions
(all combinations of Rat/Country/Days 0-150 (taking day up to 200 led to some extreme predictions that blew the vertical scale)
Combine data and predictions into a single data frame (you don't have to do this but it makes the legend easy)
Plot:
Reconstructing data: