#################################################################### ## Unix: ## /usr/bin/R -q --no-restore --no-save < telstra.r ## DOS: ## "S:\\R\\rw2001\\bin\\Rterm.exe" -q --no-restore --no-save < telstra.r #################################################################### options(echo = FALSE) #-------------------------------------------------------------------- # Enter series name: seriesname = "OLEAUSPZZP"; write(paste("series:",seriesname),file=""); bitmap(file=paste(seriesname,"png",sep="."),width=5,height=5,res=400) #png(file=seriesname,width=680,height=450,pointsize=12,bg="white",res=200); #-------------------------------------------------------------------- # Read/store data: data <- scan(paste(seriesname,"txt",sep="."), list(0,0)); x <- data[[1]]; y <- data[[2]]; #-------------------------------------------------------------------- # Store into ts objects and plot. startyear <- 2004; startperiod <- 1; freq <- 4; xts <- ts( x, start=c(startyear, startperiod), frequency=freq ); yts <- ts( y, start=c(startyear, startperiod), frequency=freq ); ts.plot(xts, yts, gpars=list(ylab="Value", col=c(1:2)), main=paste("series:",seriesname)); #-------------------------------------------------------------------- # Compute ratio: R=x/y and test for H0: R=1 vs H1: R>1(public) or R<1(private) # Apply 1-sided t-test. R <- x / y; tvalue <- (mean(R) - 1) / (sd(R)/sqrt(length(R))); # probability of obtaining value > this observed tvalue # (i.e. R > observed x/y) by chance is: if( (mean(R) > 1) && (median(R) > 1) ) { pvalue <- pt(tvalue, (length(R)-1), lower.tail=FALSE); } else if( (mean(R) < 1) && (median(R) < 1) ) { pvalue <- pt(tvalue, (length(R)-1), lower.tail=TRUE); } else { write(paste("Disaster! Check vector of ratios:"), file=""); R; mean(R); median(R); q(); } # if then say pvalue < 0.05 (5%), observed R is very unlikely # to be due to chance occurance - not consistent with R=1 hence # reject H0. # echo results to screen: R; tvalue; pvalue; mean(R); median(R); dev.off(); q();