为什么在将拟合线映射到 R 中的 xyplot 时出现错误?

问题描述

我在尝试在使用点阵库的 xyplot 函数创建的图的顶部绘制拟合值时遇到错误

Error in plot.xy(xy.coords(x,y),type = type,...) : 
  plot.new has not been called yet

我接下来的教程使用 with 函数尝试映射通过线性混合模型估计的拟合值。我发现了一些关于这个错误的讨论,所以我知道 with 语句没有找到由 xyplot 函数创建的图,但我不知道如何解决这个问题。

(https://stats.idre.ucla.edu/r/seminars/repeated-measures-analysis-with-r/)

library(lattice)
library(nlme)

study2 <- read.csv("https://stats.idre.ucla.edu/stat/data/study2.csv")
study2 <- within(study2,{
  id <- factor(id)
  exertype <- factor(exertype)
  diet <- factor(diet)
})

time.linear <- lme(pulse ~ exertype * time,random = list(id = pdDiag(~ time)),data = study2)
summary(time.linear)

fitted <- fitted(time.linear,level=0)

xyplot(pulse[exertype==1] ~ time[exertype==1],data = study2,groups = id,type = "o",ylim = c(50,150),xlim = c(0,800),panel = panel.superpose,col = "blue")

with(study2,lines(time[exertype==1],fitted[exertype==1],type = "b",col = "dark blue",lwd = 4))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)