r - 预测线图
问题描述
我用 lmer 安装了以下模型:
mod1<-lmer(logpd~arm*lspline(pday,knots=2)+(1|pid),data=q1)
我想用 ggplot 重新创建以下图:
obsmeans<-aggregate(q1$logpd,by=data.frame(q1$pday,q1$arm),mean);obsmeans
fitted<-aggregate(fitted(mod1),by=data.frame(q1$pday,q1$arm),mean);fitted
plot(obsmeans$x~fitted$q1.pday)
lines(fitted$x[which(fitted$q1.arm=="SP")]~fitted$q1.pday[which(fitted$q1.arm=="SP")],lty=1)
lines(fitted$x[which(fitted$q1.arm=="SP/ART")]~fitted$q1.pday[which(fitted$q1.arm=="SP/ART")],lty=2)
我可以用 ggplot 绘制观察到的平均值和拟合平均值,但不知道如何添加预测线?
pred<-data.frame(obsmeans,fitted)
ggplot(pred,aes(x=x,y=q1.pday))+
geom_point()
编辑
以下是观察到的平均值和拟合值:
obsmeans
q1.pday q1.arm x
1 0 SP 3.5566
2 1 SP 2.7925
3 2 SP 0.7763
4 3 SP 0.5454
5 7 SP 0.0973
6 0 SP/ART 3.4309
7 1 SP/ART 0.9286
8 2 SP/ART 0.1898
9 3 SP/ART 0.0482
10 7 SP/ART 0.0000
fitted:
q1.pday q1.arm x
1 0 SP 3.7687
2 1 SP 2.3389
3 2 SP 0.8795
4 3 SP 0.7068
5 7 SP 0.0641
6 0 SP/ART 3.1345
7 1 SP/ART 1.5416
8 2 SP/ART -0.0562
9 3 SP/ART -0.0345
10 7 SP/ART 0.0172
解决方案
推荐阅读
- sql - 文章个性化推荐系统的系统数据库设计
- javascript - 无法在用户脚本(javascript)中获取站点响应标头
- python - Django RequestFactory 不存储用户
- html - 使用材质 ui svg 图标作为背景图片
- java - 如何在 InDesign Java 文档中获得真实的页数
- matlab - 如何将二进制函数应用于元胞数组和双精度数组
- go - Golang - 如何从代码内部显示模块版本
- c++ - 在 Windows 上打开的 C++ 文件总是失败
- binding - 我可以在我的 CollectionView 中使用填充视图的 ItemsSource 列表之外的值填充标签吗?
- javascript - Flask:javascript读取时python对象到json触发错误