# Example of a change in regression at 100 in simulated normal data
set.seed(1)
x=1:250
y=c(0.01*x[1:100],1.5-0.02*(x[101:250]-101))
ynoise=y+rnorm(250,0,0.2)
data=cbind(ynoise,1,x)
single.reg.norm(data,penalty="SIC",class=FALSE) # returns 100 to show that the null hypothesis was rejected and the change in regression is at 100
ans=single.reg.norm(data,penalty="Asymptotic",value=0.01)
cpts(ans) # returns 100 to show that the null hypothesis was rejected, the change in regression is at 100 and we are 99% confident of this result
# Example of a data matrix containing 2 rows, row 1 has a change in regression and row 2 had no change in regression
set.seed(1)
x=1:250
y=c(0.01*x[1:100],1.5-0.02*(x[101:250]-101))
ynoise=y+rnorm(250,0,0.2)
data1=cbind(ynoise,1,x)
x=1:250
y=0.01*x+1
ynoise=y+rnorm(250,0,0.2)
data2=cbind(ynoise,1,x)
z=array(0,dim=c(2,250,3)) # note that the same model is fitted to all datasets
z[1,,]=data1
z[2,,]=data2
single.reg.norm(z,penalty="SIC",class=FALSE) # returns vector c(100,250) which shows that the first dataset has a change in regression at 100 and the second dataset rejected H1 and has no change in regression
ans=single.reg.norm(z,penalty="Manual",value="diffparam*log(n)")
cpts(ans[[1]]) # test using a manual penalty which is the same as the SIC penalty for this example
cpts(ans[[2]]) # result is the same as above, c(100, 250) and 250.
Run the code above in your browser using DataLab