Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在stat_smooth中添加权重和相关类型_R_Ggplot2_Statistics - Fatal编程技术网

R 在stat_smooth中添加权重和相关类型

R 在stat_smooth中添加权重和相关类型,r,ggplot2,statistics,R,Ggplot2,Statistics,是否有办法在ggplot2的stat_平滑函数中指定权重和相关类型。我正在尝试使用以下gam模式绘制平滑函数。有没有办法在stat_smooth()中指定参数 set.seed(1) 表(id=rep((1:100),10),value=rnorm(1000),分层=rep(c(“A”,“B”,“c”,“D”),25)) 设置键(D,id) D=D[,时间:=1:10,by=id] w=1/(0.1+时间)^2 模型这应该有效: set.seed(1) D = data.table(id = r

是否有办法在ggplot2的stat_平滑函数中指定权重和相关类型。我正在尝试使用以下gam模式绘制平滑函数。有没有办法在stat_smooth()中指定参数

set.seed(1)
表(id=rep((1:100),10),value=rnorm(1000),分层=rep(c(“A”,“B”,“c”,“D”),25))
设置键(D,id)
D=D[,时间:=1:10,by=id]
w=1/(0.1+时间)^2
模型这应该有效:

set.seed(1)
D = data.table(id = rep((1:100),10), value = rnorm(1000), stratification = rep(c("A","B","C","D"), 25))
setkey(D, id)
D[, time := 1:10, by = id]
D$w = 1/(0.1 + D$time)^2 
Model <- gam(formula = value~ s(time), weights=w, data=D, correlation=corAR1(form =~ time))
pred <- data.frame(time=D$time, fitted=Model$fitted.values)
ggplot(D, aes(time, value)) + 
  geom_point() +
  geom_line(data=pred,aes(time, fitted), col='steelblue', lwd=1.2)
set.seed(1)
表(id=rep((1:100),10),value=rnorm(1000),分层=rep(c(“A”,“B”,“c”,“D”),25))
设置键(D,id)
D[,时间:=1:10,by=id]
D$w=1/(0.1+D$time)^2
模型
set.seed(1)
D = data.table(id = rep((1:100),10), value = rnorm(1000), stratification = rep(c("A","B","C","D"), 25))
setkey(D, id)
D[, time := 1:10, by = id]
D$w = 1/(0.1 + D$time)^2 
Model <- gam(formula = value~ s(time), weights=w, data=D, correlation=corAR1(form =~ time))
pred <- data.frame(time=D$time, fitted=Model$fitted.values)
ggplot(D, aes(time, value)) + 
  geom_point() +
  geom_line(data=pred,aes(time, fitted), col='steelblue', lwd=1.2)