# real data
# type ?Nile for background information
nile <- data.frame(t=1871:1970, ht=Nile)
fitS(nile,1,2,10) # abrupt change model
# type ?cancerRates for background information
data(cancerRates)
fitS(cancerRates,1,2) # gradual change model
# \donttest{
# simulated data, changepoint at i = 367
n <- 500
x <- (1:n)/n
y <- vector(length=n)
trueChangePt <-round(n*2/3)
y[1:trueChangePt] <- rnorm(trueChangePt,10,2)
y[(trueChangePt+1):n] <- rnorm(n-trueChangePt,12.5,2)
d <- data.frame(x=x,y=y)
plot(d)
fitS(d,1,2,10) # abrupt
fitS(d, 1, 2) # gradual
# simulated data, changepoints at i= 383, 855
n <- 1000
y <- vector(length = n)
x <- seq(1,n,by = 1)
idx <- c(383,855)
part1 <- runif(n = length(x[1:(idx[1]-1)]), min = 0, max = 4) #mean of 2
part2 <- runif(n = length(x[idx[1]:(idx[2]-1)]), min = 0,max = 10) # mean of 5
part3 <- runif(n = length(x[idx[2]:n]), min = 0, max = 2) #mean of 1
y[1:(idx[1]-1)] <- part1
y[idx[1]:(idx[2]-1)] <- part2
y[idx[2]:n] <- part3
df <- data.frame(x = x, y = y)
fitS(df, 1, 2, depth=2, autoTraverse = TRUE)
# }
Run the code above in your browser using DataLab