Sei sulla pagina 1di 3

The given data did not present the year variable, so it was added into the dataset called

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:

The segmented regression is then:


yt = 1080 + 1.2406timet - 290.5423interventiont - 0.5468timeafter + vt
vt = 0.1567vt-1 - 0.0466vt-2 + t, where t ~ IN(0, 2)
The small p-value states that the parameter 2 is significant, which indicates that there was a
sudden shift in water level in 1899. On the other hand, p-value of 3 states that the
parameter is not significant which indicates that there was not exactly a gradual water level
shift or the slope change after the shift in water level in 1899.
The graph plots the data against two regression lines, and the vertical line shows the
intervention happens at year 1899. The parameter estimate for time is the trend before
intervention, so we are looking at the first regression line on the left. The line is slightly going
up due to fluctuations, but it is pretty flat. The parameter estimate for intervention is the
sudden change and it is negative. This means the water level dropped about 290 units. The
parameter estimate for time_after is negative and insignificant. This tells us that the trend
became negative after intervention but not significant. This parameter estimate is directed to
the second regression line on the right of the vertical line. Overall, this is flat without trend.

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;

data niledata; set nilenew; retain time_after 0;


time=_N_;
if year lt 1899 then intervention=0; else intervention=1;
if year ge 1899 then time_after=time_after+1;
run;
proc print data=niledata;
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;

title1 "Segmented Regression for Level";


symbol1 i=j width=2 c=black;
symbol2 i=j width=2.5 c=black;
proc gplot data=a;
plot(level p)*year/overlay vaxis=axis1 href=1899;
run;
quit;

Potrebbero piacerti anche