if (FALSE) {
data(wool)
XX <- wool
y <- XX[, ncol(XX)]
X <- XX[, 1:(ncol(XX)-1), drop=FALSE]
out <- fsrfan(X, y) # call 'fsrfan' with all default parameters
out <- fsrfan(cycles~., data=wool) # use the formula interface
set.seed(10)
out <- fsrfan(cycles~., data=wool, plot=TRUE) # call 'fsrfan' and produce the plot
plot(out) # use the plot method on the fsrfan object
plot(out, conflev=c(0.9, 0.95, 0.99)) # change the confidence leel in the plot method
##======================
##
## fsrfan() with all default options.
## Store values of the score test statistic for the five most common
## values of $\lambda$. Produce also a fan plot and display it on the screen.
## Common part to all examples: load 'wool' data set.
data(wool)
head(wool)
dim(wool)
## The function fsrfan() stores the score test statistic.
## In this case we use the five most common values of lambda are considered
out <- fsrfan(cycles~., data=wool)
plot(out)
## fanplot(out) # Not yet implemented in fsdaR
## The fan plot shows the log transformation is diffused throughout the data
## and does not depend on the presence of particular observations.
##======================
##
## Example specifying 'lambda'.
## Produce a fan plot for each value of 'lambda' in the vector 'la'.
## Extract in matrix 'Un' the units which entered the search in each step
data(wool)
out <- fsrfan(cycles~., data=wool, la=c(-1, -0.5, 0, 0.5), plot=TRUE)
plot(out)
out$Un[,2,]
##======================
## Example specifying the confidence level and the initial starting point for monitoring.
## Construct the fan plot specifying the confidence level and the initial starting point
## for monitoring.
data(wool)
out <- fsrfan(cycles~., data=wool, init=ncol(wool)+1, nsamp=0, conflev=0.95, plots=TRUE)
plot(out, conflev=0.95)
##=====================
## Example with starting point based on LTS.
## Extract all subsamples, construct a fan plot specifying the confidence level
## and the initial starting point for monitoring based on p+2 observations,
## strong line width for lines associated with the confidence bands.
data(wool)
out <- fsrfan(cycles~., data=wool, init=ncol(wool)+1, nsamp=0, lms=0,
lwd.env=3, plot=TRUE)
plot(out, lwd.env=3)
##=====================
## Fan plot using the loyalty cards data.
## In this example, 'la' is the vector contanining the most common values
## of the transformation parameter.
## Store the score test statistics for the specified values of lambda
## and automatically produce the fan plot
data(loyalty)
head(loyalty)
dim(loyalty)
## la is a vector contanining the most common values of the transformation parameter
out <- fsrfan(amount_spent~., data=loyalty, la=c(0, 1/3, 0.4, 0.5),
init=ncol(loyalty)+1, plot=TRUE, lwd=3)
plot(out, lwd=3)
## The fan plot shows that even if the third root is the best value of the transformation
## parameter at the end of the search, in earlier steps it lies very close to the upper
## rejection region. The best value of the transformation parameter seems to be the one
## associated with la=0.4, which is always the confidence bands but at the end of search,
## due to the presence of particular observations it goes below the lower rejection line.
##=====================
## Compare BoxCox with Yeo and Johnson transformation.
## Store values of the score test statistic for the five most common
## values of lambda. Produce also a fan plot and display it on the screen.
## Common part to all examples: load wool dataset.
data(wool)
## Store the score test statistic using Box Cox transformation.
outBC <- fsrfan(cycles~., data=wool, nsamp=0)
## Store the score test statistic using Yeo and Johnson transformation.
outYJ <- fsrfan(cycles~., data=wool, family="YJ", nsamp=0)
## Not yet fully implemented
## fanplot(outBC, main="Box Cox")
## fanplot(outYJ,main="Yeo and Johnson")
plot(outBC, main="Box Cox")
plot(outYJ, main="Yeo and Johnson")
cat("\nMaximum difference in absolute value: ",
max(max(abs(outYJ$Score - outBC$Score), na.rm=TRUE)), "\n")
##======================
## Call 'fsrfan' with Yeo-Johnson (YJ) transformation
out <- fsrfan(cycles~., data=wool, family="YJ")
plot(out)
}
Run the code above in your browser using DataLab