| Type: | Package | 
| Title: | S-Curve Fit for Changepoint Analysis | 
| Version: | 1.0.1 | 
| Maintainer: | Norm Matloff <nsmatloff@ucdavis.edu> | 
| Description: | Estimation of changepoints using an "S-curve" approximation. Formation of confidence intervals for changepoint locations and magnitudes. Both abrupt and gradual changes can be modeled. | 
| Depends: | R (≥ 3.5.0), nls.multstart, ggplot2, stringr | 
| Suggests: | knitr,rmarkdown | 
| VignetteBuilder: | knitr | 
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] | 
| URL: | https://github.com/matloff/changeS | 
| Encoding: | UTF-8 | 
| NeedsCompilation: | no | 
| Packaged: | 2024-03-23 19:46:31 UTC; normanmatloff | 
| Author: | Lan Jiang [aut],
  Collin Kennedy [aut],
  Norm Matloff | 
| Repository: | CRAN | 
| Date/Publication: | 2024-03-25 19:10:06 UTC | 
Breast Cancer Dataset
Description
Breast cancer rate for Swedish females between age of 40-50,
courtesy of Professor Y. Pawitan.
A data frame with 99 observations on the following 2 variables.
Age: Age of women having the disease.
Incidence: Number of women of that age.
S-Curve Fit
Description
Finds change(s) in mean.
Usage
fitS(dataIn,xColIndex=NULL,yColIndex=NULL,slopeIn=NULL,depth=1,
   family_wise_error_rate=0.05,autoTraverse=TRUE,plotTitle = '')
Arguments
| dataIn | Data frame or equivalent. | 
| xColIndex | Column number of "x" (typically time). | 
| yColIndex | Column number of "y". | 
| slopeIn | A fixed slope value for the model. Should be set to a large value for the abrupt-change case. If NULL, the algorithm will estimate the slope (gradual change case) | 
| depth | Upper bound for the depth of the binary segmentation ; if this is 1, the algorithm models the situation of (at most) 1 changepoint. | 
| family_wise_error_rate | Nominal alpha value for determining 
whether to proceed with the binary segmentations to the next split.
Meaningful only if  | 
| autoTraverse | If TRUE, do automatic binary segmentation.
Meaningful only of  | 
| plotTitle | Title for output plot, if any. | 
Details
Changepoint detection/estimation for changes in mean, performed by using an S-curve (logistic function) to approximate a step function. This enables asymptotic standard errors, and associated confidence intervals and tests for changepoint locations and change magnitudes. (However, in the multi-changepoint case, the alpha levels are only nominal.)
Note:  The location of a changepoint is considered to be a continuous
numeric quantity, in contrast to packages such as changepoints
where the location is integer-valued.
Value
A 'fittedS' object, containing estimates, standard errors
and so on.
Author(s)
Lan Jiang, Collin Kennedy, Norm Matloff
Examples
# 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
# 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)
S-Curve Fit, Linear Models
Description
Estimation of location and magnitudes of change in intercept and slope, for piecewise linear models.
Usage
fitS_linear(dataIn,xColIndex=NULL,yColIndex=NULL,plotTitle = '')
Arguments
| dataIn | Data frame or equivalent. | 
| xColIndex | Column number of "x" (typically time). | 
| yColIndex | Column number of "y". | 
| plotTitle | Title for output plot, if any. | 
Details
Linear model analog of fitS.  Note:  May have long run times.
Value
Object of class "fittedS_linear", with components:
| b1 | The pre-changepoint slope. | 
| h1 | The post-changepoint slope. | 
| s1 | S-curve slope for finding regression slope. | 
| c | The changepoint. | 
| b2 | Pre-changepoint intercept. | 
| h2 | Post-changepoint intercept. | 
| s2 | S-curve slope for finding regression slope. | 
The gap at the changepoint is then
(h2 + h2 c) - (b2 + b1 c)
Author(s)
Lan Jiang, Collin Kennedy, Norm Matloff