2015-10-06 57 views
0

下面是我的数据框中用于此绘图的数据的子集;ggplot印刷回归方程,其中在一个绘图上有多个lm

Year region gear Species.Code query LPUE 
1974 Cyprus creel LOB    Pre  0.31 
1975 Cyprus creel LOB    Pre  0.26 
1976 Cyprus creel LOB    Pre  0.33 
1977 Cyprus creel LOB    Pre  0.17 
1978 Cyprus creel LOB    Pre  0.2 
1979 Cyprus creel LOB    Pre  0.22 
1980 Cyprus creel LOB    Pre  0.38 
1981 Cyprus creel LOB    Pre  0.51 
1982 Cyprus creel LOB    Pre  0.57 
1983 Cyprus creel LOB    Pre  0.45 
1984 Cyprus creel LOB    Post 0.43 
1985 Cyprus creel LOB    Post 0.33 
1986 Cyprus creel LOB    Post 0.21 
1987 Cyprus creel LOB    Post 0.69 
1988 Cyprus creel LOB    Post 0.65 
1989 Cyprus creel LOB    Post 0.37 
1990 Cyprus creel LOB    Post 0.35 
1991 Cyprus creel LOB    Post 0.15 
1992 Cyprus creel LOB    Post 0.21 
1993 Cyprus creel LOB    Post 0.17 

我已生成的时间序列数据的线图和装配两个线性回归一个用于数据高达1984,一个用于数据1984 使用以下代码之后;

ggplot(subset(A7,region=="Cyprus"&gear=="creel"&Species.Code=="LOB"),aes(x=Year,y=LPUE,shape=query))+ 
    geom_line()+ 
    geom_smooth(method="lm")+ 
    theme(panel.background = element_rect(fill = 'white', colour = 'black')) 

我想先知道我可以打印在图上方程(其他例子我已经在堆栈溢出只发现了一个LM处理),其次我怎么可以保存LM模型,这样我可以对它们之间的重要性进行统计检验。

+0

你拥有的屏幕截图会有所帮助,因为你可能没有包含足够的数据来重现你拥有的内容。 –

+0

如果你想做统计测试,我建议适合ggplot以外的模型。 – Roland

+0

对不起@MikeWise我不熟悉如何添加屏幕截图。我只能看到如何从互联网上添加图片。 –

回答

2

可以通过堆叠geom_smooth命令添加几个回归线到ggplot。我建议为你想要的两个模型创建单独的数据框。

data_upto84 <- subset(A7, year<1985) 
data_from84 <- subset(A7, year>1984) 

ggplot(data_upto84, aes(YEAR, LPUE)) + 
stat_summary(fun.data=mean_cl_normal) + 
geom_smooth(method = 'lm') + 
geom_smooth(data = data_from84, aes(YEAR, LPUE), method = 'lm') 

关于你的第二个问题:“怎么其次,我可以保存LM模型,这样我可以做他们之间的显着性的统计检验”。 您可以通过将其分配给对象保存模型:

model1 <- lm(LPUE ~ 1 + YEAR, data = data_upto84) 
model2 <- lm(LPUE ~ 1 + YEAR, data = data_from84) 

你想用这些模型来测试什么目前尚不清楚给我。在两个不同的样品上运行模型时,标准模型比较(例如使用anova函数)将无效。

相关问题