有没有一种方法可以在R中绘制glm?

时间:2019-04-03 19:15:54

标签: r ggplot2

我正在寻找一个我拥有的glm.nb模型的图形。但是,我不确定模型中是否有太多变量,或者是否有可能。前三个(c,d,e)用于说明人口之间的差异。没有足够的水平将人口作为随机因素,因此我不得不以这种方式将它们包括在内。但这使我尝试绘制图形的方式变得复杂。我还想根据种区分两个线。

这是我要绘制的模型。

model1<- glm(distance~speed+species+c+d+e, data=data)

我最初尝试使用qplot,但后来我意识到这并不是基于实际模型,包括总体。

qplot(x = speed, y = distance, data = data, color = species) +
  geom_smooth(aes(group=species),method = "lm") 

然后,我尝试包含方程式,但我认为图形不正确。

equation1=equation1=function(x){coef(model1)[2]*x+coef(model1)[1]}
equation2=function(x){coef(model1)[2]*x+coef(model1)[1]+coef(model1)[3]}

ggplot(data, aes(y=distance,x=speed,color=species), geom_smooth(aes(group=species),method = "lm") )+geom_point()+
  stat_function(fun=equation1,geom="line",color=scales::hue_pal()(2)[1])+
  stat_function(fun=equation2,geom="line",color=scales::hue_pal()(2)[2])

0 个答案:

没有答案