赖江山的博客分享 http://blog.sciencenet.cn/u/laijiangshan 生态、统计与R语言

博文

比较两条回归线斜率和截距是否显著性差异(simba包)

已有 9855 次阅读 2021-6-11 16:06 |系统分类:科研笔记

研究过程,有时候需要比较两条回归的斜率和截距,可以用simba包diffslope和diffic函数。参考的文献为:Nekola, J. C. and White, P. S. (1999) The distance decay of similarity in biogeography and ecology. Journal of Biogeography 26: 867-878.

#install.packages("simba")
library(simba)

下面的代码全部是随机生成的数据,读者自己的数据读进来直接赋值给即x1,y1,x2,y2即可

x1 <- 1:10y1 <- 3*x1+7+rnorm(10)
x2 <- 2:11y2 <- 4*x2+7.2+rnorm(10)
plot(x1,y1)
abline(lm(y1~x1))
points(x2,y2,col=2)
abline(lm(y2~x2))

#斜率的差异比较,差异显著
diffslope(x1, y1, x2, y2)
## 
## Is difference in slope significant? 
## Significance is based on 1000 permutations 
## 
## Call:
## diffslope(x1 = x1, y1 = y1, x2 = x2, y2 = y2) 
## 
## Difference in Slope: -1.124 
## Significance: 0.001 
## 
## Empirical upper confidence limits of r:
##   90%   95% 97.5%   99% 
## 0.535 0.667 0.815 0.958
#截距的差异比较,差异不显著
diffic(x1, y1, x2, y2)
## 
## Is difference in slope significant? 
## Significance is based on 1000 permutations 
## 
## Call:
## diffic(x1 = x1, y1 = y1, x2 = x2, y2 = y2) 
## 
## Difference in Slope: 0.1191 
## Significance: 0.523 
## 
## Empirical upper confidence limits of r:
##   90%   95% 97.5%   99% 
##  4.19  5.10  6.23  6.77


https://blog.sciencenet.cn/blog-267448-1290778.html

上一篇:ggplot2里面的全球地图并添加物种分布的点
下一篇:rdacca.hp包1.0版本正式在CRAN发布
收藏 IP: 159.226.89.*| 热度|

1 李利平

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 04:33

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部