Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
nilenew. We then created another dataset called niledata to include the variables time_after,
time and intervention for the purpose of building a segmented regression. The parameter
estimates of the segmented regression are presented below based on the shift in water levels
starting in 1899.
Estimating changes in level and trend through segmented regression is presented as follows:
yt = 0+ 1timet + 2interventiont + 38timeafter + vt
- 0 is the average water level at time zero (before intervention)
- 1 is the baseline trend or slope (before intervention)
- 2 is the sudden change in water level after intervention in 1899
- 3 is the trend change or gradual change after intervention in 1899
- 0 + 2 is the post intervention intercept (level)
- 1 + 3 is the post intervention slope (trend)
- vt error which can be an ARMA time series
Below is the parameter estimates for our Nile River data:
As we can see from the level vs observation plot, there is a sudden drop around the 29 th (year
1899) observation, and this is what we see in the segment regression for level plot above. The
residuals look roughly normal, and the autocorrelation of residuals for level seems quickly
declined, so the series looks fairly stationary. Thus, this model appears to be appropriate.
nile = read.csv("C:\\Users\\Lusi\\Desktop\\nile.csv")
attach(nile)
nile$Obs = 1871:1970
year = nile$Obs
level = nile$level
nilenew = data.frame(year, level)
library(foreign)
write.foreign(nile, "C:\\Users\\Lusi\\Desktop\\nilenew.xls",
"C:\\Users\\Lusi\\Desktop\\nilenew.sas", package="SAS")
/* Question 1 */
/* Adding a Year Variable */
data nilenew;
infile "C:\Users\Lusi\Desktop\nilenew.xls"
dsd lrecl= 13 ;
input
year
level
;
run;
proc print data=nilenew;
run;
/* Segmented Regression */
title 'Segmented Regression';
proc autoreg data=niledata;
model level=time intervention time_after/method=ml nlag=2;
output out=a pm=p residual=r ucl=u lcl=l;
ods output ParameterEstimatesGivenAR=ap;
run;