简体   繁体   中英

R How to calculate the intercept of sen's slope function from trend package?

I want to estimate the precipitation trends (in percentage) at long-term. At the first time, I calculate the sen's slope from the "trend package" but it misses the intercept to apply this linear equation to find the predicted value of each year:

f(S) = QS + B (Q : sen's slope, S : parameter, B : intercept)

I use this example to explain my problematic:

# import data
require(trend)
data("maxau")
maxau

# Estimate Annual trend with sen's slope

s <- maxau[,"s"]
sens.slope(s) # equal to  -0.2876139 / year

Can you help me how to calculate the intercpt (B) of f(S) equation in order to calculate the predicted value of S parameter for each year ?

Thank you in advance for your help !

i had undestood that the R 'trend' package doesn't generate the intercept of Sen's slope

you can try using the 'zyp' package which generates the intercept based on the median of the values 式 .

here is the documentation of the zyp package and this is an example with dataframe

library(zyp)
df=data.frame(x=c(1,2,3,4,5),y=c(3,6,8,1,9))
zyp.sen(y~x,df)

documentation: https://cran.r-project.org/web/packages/zyp/zyp.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM