r - Make regression equation in monthly time series data in Rstudio? -


i'd analysis of monthly rainfall data (make time series plot + regression equation time series). i've written code in r , plot monthly time series data , i've tried make different regression equations (linear , nor linear) , show these equation on same graph of time series plot unfortunately cannot may because i'm new user of r/ rstudio statistical packages. can me? many in advance.

data style date   monthly rainfall (mm) jan94     12 feb94      11 . . . dec14    1x 

the code

# plotting of time series rainfall data (option1) # step1: read files  mr<-read.table("c:\\users\\salam\\desktop\\trend kufa\\csv2 habel\\monthly rainfall.csv", header=t,sep=",")  summary(mr) names(mr) mr  # step2: plot observed discharge  mr1<-mr[c(1:252),2];  summary (mr1) mr1 class(mr1)  require(zoo)  x <- yearmon(1994 + seq(0, 251)/12) x  y<-mr1 y  pcp<-y~x  plot(pcp,type="l", xlab="month",ylab="monthly rainfall(mm)", axes=t)   grid(nx=250, ny=250, col="lightgray", lty="solid") lines(pcp,lwd=2, col="blue")  box(which='plot') title("monthly observed rainfall(mm)")  ##  regression    s1 <- lm(y ~ z, data=mr) abline(s1,col='red',lwd=3) summary(s1)   s2<-lm( y~poly(x,3), data=mr) summary(s2) abline(s2,col='green',lwd=3)  s3 <- nls(y ~ exp(a + b / x),start = list(a = 0, b = 0)) summary(s3)  s4 <- nls(y ~ (a + b *log( x)), start = list(a = 0, b = 0)) summary(s4)  

you can use text function put equations on plots.

text(x, y, "s1 <- lm(y ~ z, data=x)",      cex = .8) 

the x , y coordinates on plot equation

put equation in quotes

data data frame

cex controls font size

for more info & options on text use ?text


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -