8/26/2021 3:39:51 PM
在对一些时间序列数据进行线性拟合的时候,最方便的是在Excel中添趋势线,同时显示公式与R值,但是我们需要对其进行P值计算以检验该趋势是否具有显著性,此外,置信区间也是一个需要考虑是否进行显示的问题。
library(basicTrendline)
library(readxl)
#读取的excel文件中只有两列数据,"year"和"area"
data <- read_excel("D:/00GBAWater/06CODE/df.xlsx")
x <- c(1, 3, 6, 9, 13, 17)
y <- c(5, 8, 11, 13, 13.2, 13.5)
直线拟合:默认(自动添加95%置信区间)
trendline(data$year,data$area, model="line2P", ePos.x = "topleft", summary=TRUE, eDigit=5)
使用
trendline(x, y, model = "line2P", Pvalue.corrected = TRUE,
linecolor = "blue", lty = 1, lwd = 1,
show.equation = TRUE, show.Rpvalue = TRUE,
Rname = 1, Pname = 0, xname = "x", yname = "y",
yhat = FALSE,
summary = TRUE,
ePos.x = NULL, ePos.y = NULL, text.col = "black", eDigit = 5, eSize = 1,
CI.fill = TRUE, CI.level = 0.95, CI.color = "grey", CI.alpha = 1, CI.lty = 1, CI.lwd = 1,
las = 1, xlab = NULL, ylab = NULL, ...)
主要参数设置
- “line2P” (formula as: y=a*x+b),
-
- “line3P” (y=ax2+bx+c),
-
- “log2P” (y=a*ln(x)+b),
-
- “exp2P” (y=aebx),
-
- “exp3P” (y=aebx+c),
-
- “power2P” (y=a*xb),
-
- “power3P” (y=a*xb+c).
参考链接:
http://blog.sciencenet.cn/blog-651374-1126673.html
|
请发表评论