# Create an Interval-Data object containing the intervals for 899 observations
# on the temperatures by quarter in 60 Chinese meteorological stations.
ChinaT <- IData(ChinaTemp[1:8],VarNames=c("T1","T2","T3","T4"))
#Display the first and last observations
head(ChinaT)
tail(ChinaT)
#Print summary statistics
summary(ChinaT)
#Create a new data set considering only the Winter (1st and 4th) quarter intervals
ChinaWT <- ChinaT[,c(1,4)]
# Estimate parameters by maximum likelihood, assuming
# the classical (unrestricted) covariance configuration C1
ChinaWTE.C1 <- mle(ChinaWT,Config=1)
cat("Winter temperatures of China -- maximum likelhiood estimation results:\n")
print(ChinaWTE.C1)
cat("Standard Errors of Estimators:\n") ; print(stdEr(ChinaWTE.C1))
# Estimate parameters by maximum likelihood,
# assuming that one of the C3, C4 or C5 restricted covariance configurations holds
ChinaWTE.C345 <- mle(ChinaWT,Config=3:5)
cat("Winter temperatures of China -- maximum likelhiood estimation results:\n")
print(ChinaWTE.C345)
cat("Standard Errors of Estimators:\n") ; print(stdEr(ChinaWTE.C345))
#MANOVA tests assuming that configuariton 1 (unrestricted covariance)
# or 4 (MidPoints independent of Log-Ranges) holds.
ManvChinaWT.C14 <- MANOVA(ChinaWT,ChinaTemp$GeoReg,Config=c(1,4))
cat("Winter temperatures of China -- MANOVA by geografical regions results:\n")
print(ManvChinaWT.C14)
#Linear Discriminant Analysis
ChinaWT.lda <- lda(ManvChinaWT.C14)
cat("Winter temperatures of China -- linear discriminant analysis results:\n")
print(ChinaWT.lda)
cat("lda Prediction results:\n")
print(predict(ChinaWT.lda,ChinaWT)$class)
#Estimate error rates by ten-fold cross-validation
CVlda <- DACrossVal(ChinaWT,ChinaTemp$GeoReg,TrainAlg=lda,
Config=BestModel(ManvChinaWT.C14@H1res),CVrep=1)
summary(CVlda[,,"Clerr"])
glberrors <-
apply(CVlda[,,"Nk"]*CVlda[,,"Clerr"],1,sum)/apply(CVlda[,,"Nk"],1,sum)
cat("Average global classification error =",mean(glberrors),"\n")
Run the code above in your browser using DataLab