| Title: | Companion to Applied Linear Statistical Models |
|---|---|
| Description: | Functions and Data set presented in Applied Linear Statistical Models Fifth Edition (Chapters 1-9 and 16-25), Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li, 2005. (ISBN-10: 0071122214, ISBN-13: 978-0071122214) that do not exist in R, are gathered in this package. The whole book will be covered in the next versions. Compatibility updates by Renova. |
| Authors: | Ali Ghanbari [aut, cre] |
| Maintainer: | Ali Ghanbari <[email protected]> |
| License: | GPL-2 | GPL-3 |
| Version: | 0.2.0.9001 |
| Built: | 2026-11-19 06:38:50 UTC |
| Source: | https://github.com/renova-r/ALSM |
ABT Electronics Corporation dataset
data("ABTElectronicsCorporation")data("ABTElectronicsCorporation")
A data frame with 40 observations on the following 3 variables.
yresponse variable
groupfactor variable
rowindex corresponding to each response
data(ABTElectronicsCorporation) ## maybe str(ABTElectronicsCorporation) ; plot(ABTElectronicsCorporation) ...data(ABTElectronicsCorporation) ## maybe str(ABTElectronicsCorporation) ; plot(ABTElectronicsCorporation) ...
Akaike's information criterion
AICp(model)AICp(model)
model |
model of regression |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. page 360
#### example page 360 AICp(lm(lny~x4,SurgicalUnit))#### example page 360 AICp(lm(lny~x4,SurgicalUnit))
Aligned dot plot specific variable correspond to two factor
aligned.dot.plot2(y, factor1, factor2)aligned.dot.plot2(y, factor1, factor2)
y |
variable based on plot aligned dot plot |
factor1 |
first factor variable |
factor2 |
second factor variable |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition.
library('ALSM') y=CashOffers$y A=CashOffers$A B=CashOffers$B aligned.dot.plot2(y,A,B)library('ALSM') y=CashOffers$y A=CashOffers$A B=CashOffers$B aligned.dot.plot2(y,A,B)
ApexEnterprises
data("ApexEnterprises")data("ApexEnterprises")
A data frame with 20 observations on the following 3 variables.
ya numeric vector
officera numeric vector
candidatea numeric vector
neter
data(ApexEnterprises) ## maybe str(ApexEnterprises) ; plot(ApexEnterprises) ...data(ApexEnterprises) ## maybe str(ApexEnterprises) ; plot(ApexEnterprises) ...
Auditor Training (10 block)
data("AuditorTraining_10")data("AuditorTraining_10")
A data frame with 30 observations on the following 3 variables.
ya numeric vector
blocka numeric vector
factora numeric vector
xcovariate
data(AuditorTraining_10) ## maybe str(AuditorTraining_10) ; plot(AuditorTraining_10) ...data(AuditorTraining_10) ## maybe str(AuditorTraining_10) ; plot(AuditorTraining_10) ...
Auditor Training ( 5 block)
data("AuditorTraining_5")data("AuditorTraining_5")
A data frame with 30 observations on the following 4 variables.
ya numeric vector
blocka numeric vector
factora numeric vector
numa numeric vector
data(AuditorTraining_5) ## maybe str(AuditorTraining_5) ; plot(AuditorTraining_5) ...data(AuditorTraining_5) ## maybe str(AuditorTraining_5) ; plot(AuditorTraining_5) ...
best subsets according to a specified criterion are identified without requiring the fitting of all of the possible subset regression models.
BestSub(x,y,method=c('r2','r2adj','sse','cp','press','aic','sbc'),num=2)BestSub(x,y,method=c('r2','r2adj','sse','cp','press','aic','sbc'),num=2)
x |
matrix of predictors |
y |
response vector |
method |
best subsets according to this specified criterion. R2,R2adj,sse,cp,press,aic and sbc. |
num |
number of best subset model per number of predictor variable. |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition.chapter 9
## page 363 library("leaps") BestSub(SurgicalUnit[,1:8],SurgicalUnit[,10],method='r2',num=2)## page 363 library("leaps") BestSub(SurgicalUnit[,1:8],SurgicalUnit[,10],method='r2',num=2)
Tests for Constancy of Error Variance between two group
bftest(fit,group,alpha=.05)bftest(fit,group,alpha=.05)
fit |
model of regression |
group |
vector, determine two group |
alpha |
Type I error level |
length group and number of observations should be equal
test statistic, p.value, alpha and degree of freedom
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .page 116
################### EXAMPLE PAGE 117 ### Group g<-rep(1,25) g[TolucaCompany$x<=70]=0 ### TEST bftest(lm(y~x,TolucaCompany),g)################### EXAMPLE PAGE 117 ### Group g<-rep(1,25) g[TolucaCompany$x<=70]=0 ### TEST bftest(lm(y~x,TolucaCompany),g)
study of the relation of amount of body fat (Y) to several possible predictor variables, based on a sample of 20 healthy females 25-34 years old
data("BodyFat")data("BodyFat")
A data frame with 20 observations on the following 4 variables.
x1a numeric vector
x2a numeric vector
x3a numeric vector
ya numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .TABLE 7.1 page 257
data(BodyFat) ## maybe str(BodyFat) ; plot(BodyFat) ...data(BodyFat) ## maybe str(BodyFat) ; plot(BodyFat) ...
transformation from the family of power transformations on Y. box-cox transformation according to SSE.
also plot SSE against lambda
boxcox.sse(x,y,l=seq(-2,2,.1))boxcox.sse(x,y,l=seq(-2,2,.1))
x |
vector predictor variable |
y |
vector response variable |
l |
vector, Different values of lambda |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition.page 134
### table 3.9 & figure 3.17 (page 136) boxcox.sse(Plasma[,1],Plasma[,2]) ### table 18.6 page 792 boxcox.sse(factor(ServoData[,2]),ServoData[,1])### table 3.9 & figure 3.17 (page 136) boxcox.sse(Plasma[,1],Plasma[,2]) ### table 18.6 page 792 boxcox.sse(factor(ServoData[,2]),ServoData[,1])
Cash Offers dataset
data("CashOffers")data("CashOffers")
A data frame with 36 observations on the following 3 variables.
yresponse variable
Afactor variable
Bfactor variable
numindex corresponding to each response
xcovariate
data(CashOffers) ## maybe str(CashOffers) ; plot(CashOffers) ...data(CashOffers) ## maybe str(CashOffers) ; plot(CashOffers) ...
Castle Bakery data set
data("CastleBakery")data("CastleBakery")
A data frame with 12 observations on the following 4 variables.
ya numeric vector
Aa numeric vector
Ba numeric vector
numa numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. Table 19.7
data(CastleBakery) ## maybe str(CastleBakery) ; plot(CastleBakery) ...data(CastleBakery) ## maybe str(CastleBakery) ; plot(CastleBakery) ...
Estimation of Mean Response and Prediction of New Observation:
Interval Estimation of E{Y_h}
Confidence Region for Regression Surface. WorkingHotelling confidence band
Simultaneous Confidence Intervals for Several Mean Responses ( Working-Hotelling, Bonferroni confidence limit )
Prediction of New Observation Yh(new)
Prediction of Mean of m New Observations at Xh
Predictions of g New Observations. Simultaneous Scheffe prediction limits for g new observations at g different levels X_h
ci.reg(model, newdata, type = c("b", "s","w","n","m","nm","gn"), alpha = 0.05,m=1)ci.reg(model, newdata, type = c("b", "s","w","n","m","nm","gn"), alpha = 0.05,m=1)
model |
model of regression |
newdata |
Data frame, New data on which the point estimate and confidencr interval is calculated. |
type |
Type of confidence interval |
alpha |
Confidence interval calculate with 1- |
m |
When use "type=nm", m is equal, new observations are to be selected at the same levels x_h |
Type values:
b Simultaneous Confidence Intervals for Several Mean Responses by Bonferroni simultaneous confidence intervals.
s Simultaneous Scheffe prediction limits for g new observations at g different levels x_h
w Confidence Region for Regression Surface or Simultaneous Confidence Intervals for Several Mean Responses
n Prediction of New Observation.
m Mean response of New Observation.
nm When In new observations are to be selected at the same levels X_h and their mean Yh(new) is to be predicted
gn Simultaneous Bonferroni prediction limits for g new observations at g different levels X_h
NOTE: for the rest of the type states, m = 1.
calculate estimation and cofidence interval
by default, type is 'b'
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition
#### problem 6.14.a page 250 d<-data.frame(282000,7.1,0) ci.reg(lm(y~x1+x2+x3,GroceryRetailer),d,type='nm',m=3) #### problem 6.13.b page 250 d<-data.frame(c(230000,250000,280000,340000),c(7.5,7.3,7.1,6.9),c(0,0,0,0)) ci.reg(lm(y~x1+x2+x3,GroceryRetailer),d,type='gn') #### problem 6.12.a page 250 d<-data.frame(c(302000,245000,280000,350000,295000),c(7.2,7.4,6.9,7,6.7),c(0,0,0,0,1)) ci.reg(lm(y~x1+x2+x3,GroceryRetailer),d,type='b') ### example page 158 d<-data.frame(c(30,65,100)) ci.reg(lm(y~x,TolucaCompany),d,type='w',alpha=.1) ### example page 54 d<-data.frame(65) ci.reg(lm(y~x,TolucaCompany),d,type='m',alpha=.1) ### example page 59 d<-data.frame(100) ci.reg(lm(y~x,TolucaCompany),d,type='n',alpha=.1)#### problem 6.14.a page 250 d<-data.frame(282000,7.1,0) ci.reg(lm(y~x1+x2+x3,GroceryRetailer),d,type='nm',m=3) #### problem 6.13.b page 250 d<-data.frame(c(230000,250000,280000,340000),c(7.5,7.3,7.1,6.9),c(0,0,0,0)) ci.reg(lm(y~x1+x2+x3,GroceryRetailer),d,type='gn') #### problem 6.12.a page 250 d<-data.frame(c(302000,245000,280000,350000,295000),c(7.2,7.4,6.9,7,6.7),c(0,0,0,0,1)) ci.reg(lm(y~x1+x2+x3,GroceryRetailer),d,type='b') ### example page 158 d<-data.frame(c(30,65,100)) ci.reg(lm(y~x,TolucaCompany),d,type='w',alpha=.1) ### example page 54 d<-data.frame(65) ci.reg(lm(y~x,TolucaCompany),d,type='m',alpha=.1) ### example page 59 d<-data.frame(100) ci.reg(lm(y~x,TolucaCompany),d,type='n',alpha=.1)
Coin Operated Tenninals
data("CoinOperatedTenninals")data("CoinOperatedTenninals")
A data frame with 8 observations on the following 3 variables.
ya numeric vector
Aa numeric vector
Ba numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. problem 20.2
data(CoinOperatedTenninals) ## maybe str(CoinOperatedTenninals) ; plot(CoinOperatedTenninals) ...data(CoinOperatedTenninals) ## maybe str(CoinOperatedTenninals) ; plot(CoinOperatedTenninals) ...
Computerized Game dataset
data("ComputerizedGame")data("ComputerizedGame")
A data frame with 80 observations on the following 3 variables.
ya numeric vector
groupa numeric vector
numa numeric vector
data(ComputerizedGame) ## maybe str(ComputerizedGame) ; plot(ComputerizedGame) ...data(ComputerizedGame) ## maybe str(ComputerizedGame) ; plot(ComputerizedGame) ...
Mallows' Cp Criterion
cpc(r,f)cpc(r,f)
r |
Reduced model |
f |
Full model |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .page 358
#### example page 358 cpc(lm(lny~x4,SurgicalUnit),lm(lny~x1+x2+x3+x4,SurgicalUnit))#### example page 358 cpc(lm(lny~x4,SurgicalUnit),lm(lny~x1+x2+x3+x4,SurgicalUnit))
CrackerPromotion
data("CrackerPromotion")data("CrackerPromotion")
A data frame with 15 observations on the following 4 variables.
ya numeric vector
xa numeric vector
treatmenta numeric vector
storea numeric vector
data(CrackerPromotion) ## maybe str(CrackerPromotion) ; plot(CrackerPromotion) ...data(CrackerPromotion) ## maybe str(CrackerPromotion) ; plot(CrackerPromotion) ...
DiskDriveService
data("DiskDriveService")data("DiskDriveService")
A data frame with 45 observations on the following 4 variables.
ya numeric vector
Aa numeric vector
Ba numeric vector
numa numeric vector
data(DiskDriveService) ## maybe str(DiskDriveService) ; plot(DiskDriveService) ...data(DiskDriveService) ## maybe str(DiskDriveService) ; plot(DiskDriveService) ...
Filling Machines dataset
data("FillingMachines")data("FillingMachines")
A data frame with 120 observations on the following 3 variables.
yresponse variable
groupfactor variable
rowindex corresponding to each response
data(FillingMachines) ## maybe str(FillingMachines) ; plot(FillingMachines) ...data(FillingMachines) ## maybe str(FillingMachines) ; plot(FillingMachines) ...
A large, national grocery retailer tracks productivity and costs of its facilities closely.
data("GroceryRetailer")data("GroceryRetailer")
A data frame with 52 observations on the following 4 variables.
ya numeric vector
x1a numeric vector
x2a numeric vector
x3a numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .problem 6.9 page 249
data(GroceryRetailer) ## maybe str(GroceryRetailer) ; plot(GroceryRetailer) ...data(GroceryRetailer) ## maybe str(GroceryRetailer) ; plot(GroceryRetailer) ...
GrowthHormone
data("GrowthHormone")data("GrowthHormone")
A data frame with 14 observations on the following 4 variables.
ya numeric vector
Aa numeric vector
Ba numeric vector
numa numeric vector
data(GrowthHormone) ## maybe str(GrowthHormone) ; plot(GrowthHormone) ...data(GrowthHormone) ## maybe str(GrowthHormone) ; plot(GrowthHormone) ...
Hay Fever Relief dataset
data("HayFeverRelief")data("HayFeverRelief")
A data frame with 36 observations on the following 4 variables.
yresponse variable
Afactor A variable
Bfactor B variable
rowindex corresponding to each response
data(HayFeverRelief) ## maybe str(HayFeverRelief) ; plot(HayFeverRelief) ...data(HayFeverRelief) ## maybe str(HayFeverRelief) ; plot(HayFeverRelief) ...
Helicopter Service dataset
data("HelicopterService")data("HelicopterService")
A data frame with 80 observations on the following 3 variables.
ya numeric vector
groupa numeric vector
numa numeric vector
data(HelicopterService) ## maybe str(HelicopterService) ; plot(HelicopterService) ...data(HelicopterService) ## maybe str(HelicopterService) ; plot(HelicopterService) ...
A personnel officer in a governmental agency administered four newly developed aptitude tests to each of 25 applicants for entry-level clerical positions in the agency
data("JobProficiency")data("JobProficiency")
A data frame with 25 observations on the following 5 variables.
ya numeric vector
x1a numeric vector
x2a numeric vector
x3a numeric vector
x4a numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .problem 9.10 page 377
data(JobProficiency) ## maybe str(JobProficiency) ; plot(JobProficiency) ...data(JobProficiency) ## maybe str(JobProficiency) ; plot(JobProficiency) ...
25 additional applicants for entry-level clerical positions in the ,agency were similarly tested and hired irrespcctive of their test scores.
data("JobProficiencyAdditional")data("JobProficiencyAdditional")
A data frame with 25 observations on the following 5 variables.
ya numeric vector
x1a numeric vector
x2a numeric vector
x3a numeric vector
x4a numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .problem 9.22 page 380
data(JobProficiencyAdditional) ## maybe str(JobProficiencyAdditional) ; plot(JobProficiencyAdditional) ...data(JobProficiencyAdditional) ## maybe str(JobProficiencyAdditional) ; plot(JobProficiencyAdditional) ...
Kenton Food Company dataset
data("KentonFoodCompany")data("KentonFoodCompany")
A data frame with 19 observations on the following 3 variables.
yresponse variable
groupfactor variable
rowindex corresponding to each response
data(KentonFoodCompany) ## maybe str(KentonFoodCompany) ; plot(KentonFoodCompany) ...data(KentonFoodCompany) ## maybe str(KentonFoodCompany) ; plot(KentonFoodCompany) ...
MLS
MLS(MSE1, df1, c1, MSE2, df2, c2, alpha = 0.05)MLS(MSE1, df1, c1, MSE2, df2, c2, alpha = 0.05)
MSE1 |
mean square of the first source of variation (with |
df1 |
df1 |
c1 |
c1 |
MSE2 |
mse2 |
df2 |
df2 |
c2 |
c2 |
alpha |
a |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. chapter 25.
##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (MSE1, df1, c1, MSE2, df2, c2, alpha = 0.05) { f1 = qf(1 - alpha/2, df1, Inf) f2 = qf(1 - alpha/2, df2, Inf) f3 = qf(1 - alpha/2, Inf, df1) f4 = qf(1 - alpha/2, Inf, df2) f5 = qf(1 - alpha/2, df1, df2) f6 = qf(1 - alpha/2, df2, df1) g1 <- 1 - 1/f1 g2 <- 1 - 1/f2 g3 <- (((f5 - 1)^2) - ((g1 * f5)^2) - ((f4 - 1)^2))/f5 g4 <- f6 * ((((f6 - 1)/f6)^2) - 1 * (((f3 - 1)/f6)^2) - g2^2) hl <- sqrt(((g1 * c1 * MSE1)^2) + (((f4 - 1) * c2 * MSE2)^2) - 1 * ((g3 * c1 * c2 * MSE1 * MSE2))) hu <- sqrt((((f3 - 1) * c1 * MSE1)^2) + ((g2 * c2 * MSE2)^2) - 1 * ((g4 * c1 * c2 * MSE1 * MSE2))) l = c1 * MSE1 + c2 * MSE2 L = sum(l) lower <- L - hl upper <- L + hu return(cbind(estimate = L, lower = lower, upper = upper)) }##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (MSE1, df1, c1, MSE2, df2, c2, alpha = 0.05) { f1 = qf(1 - alpha/2, df1, Inf) f2 = qf(1 - alpha/2, df2, Inf) f3 = qf(1 - alpha/2, Inf, df1) f4 = qf(1 - alpha/2, Inf, df2) f5 = qf(1 - alpha/2, df1, df2) f6 = qf(1 - alpha/2, df2, df1) g1 <- 1 - 1/f1 g2 <- 1 - 1/f2 g3 <- (((f5 - 1)^2) - ((g1 * f5)^2) - ((f4 - 1)^2))/f5 g4 <- f6 * ((((f6 - 1)/f6)^2) - 1 * (((f3 - 1)/f6)^2) - g2^2) hl <- sqrt(((g1 * c1 * MSE1)^2) + (((f4 - 1) * c2 * MSE2)^2) - 1 * ((g3 * c1 * c2 * MSE1 * MSE2))) hu <- sqrt((((f3 - 1) * c1 * MSE1)^2) + ((g2 * c2 * MSE2)^2) - 1 * ((g4 * c1 * c2 * MSE1 * MSE2))) l = c1 * MSE1 + c2 * MSE2 L = sum(l) lower <- L - hl upper <- L + hu return(cbind(estimate = L, lower = lower, upper = upper)) }
SSEp, R2.p, R2.adj.p, Cp, AICp, SBCp and PRESSP Values for All Possible Regression Modes
model.s(x,y)model.s(x,y)
x |
matrix of predictors |
y |
response vector |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .chapter 9
### table 9.2, page 353 library("leaps") model.s(SurgicalUnit[,1:4],SurgicalUnit[,10])### table 9.2, page 353 library("leaps") model.s(SurgicalUnit[,1:4],SurgicalUnit[,10])
Compare (estimation, SE estimation, PRESSp, AICp, SBSp, R2 , R2.adj, MSE) Training and validition data
modelval(building.set,response.building, prediction.set, response.prediction)modelval(building.set,response.building, prediction.set, response.prediction)
building.set |
matrix predictor Training data |
response.building |
vector response Training data |
prediction.set |
matrix predictor Validation data |
response.prediction |
vector response Validation data |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .chapter 9
#### page 373 (table) b<-SurgicalUnit p<-SurgicalUnitAdditional modelval(b[,c(1,2,3,8)],b[,10],p[,c(1,2,3,8)],p[,10]) modelval(b[,c(1,2,3,5,6,8)],b[,10],p[,c(1,2,3,5,6,8)],p[,10])#### page 373 (table) b<-SurgicalUnit p<-SurgicalUnitAdditional modelval(b[,c(1,2,3,8)],b[,10],p[,c(1,2,3,8)],p[,10]) modelval(b[,c(1,2,3,5,6,8)],b[,10],p[,c(1,2,3,5,6,8)],p[,10])
normal correation test
normal.cor.test(residuals, MSE)normal.cor.test(residuals, MSE)
residuals |
residual |
MSE |
MSE |
neter
##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (residuals, MSE) { w <- 1:length(residuals) r <- cor(sort(residuals), sqrt(MSE) * (qnorm((w - 0.375)/(length(residuals) + 0.25)))) return(r) }##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (residuals, MSE) { w <- 1:length(residuals) r <- cor(sort(residuals), sqrt(MSE) * (qnorm((w - 0.375)/(length(residuals) + 0.25)))) return(r) }
onerandom effect model.
onerandom(y, treatment, alpha)onerandom(y, treatment, alpha)
y |
y |
treatment |
tr |
alpha |
a |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. chapter 25.
##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (y, treatment, alpha) { treatment <- factor(treatment) aov = Anova(lm(y ~ treatment), type = 2) mse2 <- aov[, 1]/aov[, 2] mse <- mse2[2] mstr <- mse2[1] r <- aov[1, 2] + 1 n <- (aov[2, 2] + r)/r s <- sqrt(mstr/(r * n)) lower <- mean(y) - qt(1 - alpha/2, r - 1) * s upper <- mean(y) + qt(1 - alpha/2, r - 1) * s out.mu <- cbind(estimate = mean(y), lower = lower, upper = upper) l = ((mstr/mse) * (1/qf(1 - alpha/2, r - 1, r * (n - 1))) - 1)/n u = ((mstr/mse) * (1/qf(alpha/2, r - 1, r * (n - 1))) - 1)/n lower <- l/(l + 1) upper <- u/(1 + u) out.prop.sigma2.mu <- cbind(lower = lower, upper = upper) lower <- (r * (n - 1) * mse)/(qchisq(1 - alpha/2, r * (n - 1))) upper <- (r * (n - 1) * mse)/(qchisq(alpha/2, r * (n - 1))) out.sigma2 <- cbind(lower = lower, upper = upper) out1 <- satterthwaite(c = c(1/n, -1/n), MSE = c(mstr, mse), df = c(r - 1, r * (n - 1)), alpha = alpha) out2 <- MLS(MSE1 = mstr, df1 = r - 1, c1 = 1/n, MSE2 = mse, df2 = r * (n - 1), c2 = -1/n, alpha = alpha) o <- list(anova = aov, mu = out.mu, prop.sigma2.mu = out.prop.sigma2.mu, sigma2 = out.sigma2, sigma2.mu.satterthwaite = out1, sigma2.mu.MLS = out2) return(o) }##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (y, treatment, alpha) { treatment <- factor(treatment) aov = Anova(lm(y ~ treatment), type = 2) mse2 <- aov[, 1]/aov[, 2] mse <- mse2[2] mstr <- mse2[1] r <- aov[1, 2] + 1 n <- (aov[2, 2] + r)/r s <- sqrt(mstr/(r * n)) lower <- mean(y) - qt(1 - alpha/2, r - 1) * s upper <- mean(y) + qt(1 - alpha/2, r - 1) * s out.mu <- cbind(estimate = mean(y), lower = lower, upper = upper) l = ((mstr/mse) * (1/qf(1 - alpha/2, r - 1, r * (n - 1))) - 1)/n u = ((mstr/mse) * (1/qf(alpha/2, r - 1, r * (n - 1))) - 1)/n lower <- l/(l + 1) upper <- u/(1 + u) out.prop.sigma2.mu <- cbind(lower = lower, upper = upper) lower <- (r * (n - 1) * mse)/(qchisq(1 - alpha/2, r * (n - 1))) upper <- (r * (n - 1) * mse)/(qchisq(alpha/2, r * (n - 1))) out.sigma2 <- cbind(lower = lower, upper = upper) out1 <- satterthwaite(c = c(1/n, -1/n), MSE = c(mstr, mse), df = c(r - 1, r * (n - 1)), alpha = alpha) out2 <- MLS(MSE1 = mstr, df1 = r - 1, c1 = 1/n, MSE2 = mse, df2 = r * (n - 1), c2 = -1/n, alpha = alpha) o <- list(anova = aov, mu = out.mu, prop.sigma2.mu = out.prop.sigma2.mu, sigma2 = out.sigma2, sigma2.mu.satterthwaite = out1, sigma2.mu.MLS = out2) return(o) }
Fitting of ANOVA Model
Analysis of Variance (test & table)
Test and confidence interval for Single Factor level Mean
inferences for Difference between Two Factor level Means
Contrast of Factor level Means
test and confidence interval for linear Combination of Factor level Means
Analysis of Means (CI for treatment effects)
*** Tests for Constancy of Error Variance: ***
Hartley Test
Brown-Forsythe Test
*** Simultaneos Inference Procedures: ***
Tukey multiple comparison procedure
Scheffe multiple comparison procedure
Bonferroni multiple comparison procedure
*** Nonparametric ***
Nonparametric Rank F Test and multiple Pairwise Testing Procedure
***A variety of residuals in the output: ***
residuals
semistudentized residuals
studentized residuals
studentized deleted residuals
*** PLOT ***
boxplot by factors
Line Plot of Estimated Factor Level Mean
Bar Graph and Main Effects Plot
bar graph and the main etfects plot of factor level means is to display the confidence limits
*** PLOT for residuals: ***
against fitted value
Aligned Residual Dot Plot
Normal Q-Q plot
histogram
boxplot
oneway(y, group, alpha=0.05,MSE=NULL, c.value=0, mc=NULL, residual,omission.variable=NULL)oneway(y, group, alpha=0.05,MSE=NULL, c.value=0, mc=NULL, residual,omission.variable=NULL)
y |
vector, response variable |
group |
vector INTEGER, group variable |
alpha |
Confidence interval calculate with 1-alpha percent |
MSE |
mean squre of error |
c.value |
c value for single factor test. H_0: mu_i=c |
mc |
Matrix contrast(s), Each row was included in a contrast |
residual |
Type of residuals. simple (default), semistudentized, studentized or studentized.deleted |
omission.variable |
numeric vector. Omission of Important Explanatory Variables. Residual analysis may also be used to study whether or not the single-factor ANOVA model is an adequate model. |
test & CI
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. chapter 16, 17 and 18
library('ALSM') library('SuppDists') with(KentonFoodCompany,oneway(y,group,mc=matrix(c(.5,.5,-.5,-.5),1,4)))library('ALSM') library('SuppDists') with(KentonFoodCompany,oneway(y,group,mc=matrix(c(.5,.5,-.5,-.5),1,4)))
Data on age (X) and plasma level of a polyamine (Y) for a portion of the 25 healthy children in a study
data("Plasma")data("Plasma")
A data frame with 25 observations on the following 3 variables.
xa numeric vector
ya numeric vector
log.ya numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .TABLE 3.8 page 133
data(Plasma) ## maybe str(Plasma) ; plot(Plasma) ...data(Plasma) ## maybe str(Plasma) ; plot(Plasma) ...
plot R2.p, R2.adj.p, Cp, AICp, SBCp and PRESSP Values for All Possible Regression Modes
plotmodel.s(x,y)plotmodel.s(x,y)
x |
matrix of predictors |
y |
response vector |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .chapter 9
### figure 9.4, page 356 plotmodel.s(SurgicalUnit[,1:4],SurgicalUnit[,10])### figure 9.4, page 356 plotmodel.s(SurgicalUnit[,1:4],SurgicalUnit[,10])
Dwaine Studios, Inc., operates portrait studios in 21 cities of medium size. These studios specialize in p0l1raits of children
data("PortraitStudio")data("PortraitStudio")
A data frame with 21 observations on the following 3 variables.
x1a numeric vector
x2a numeric vector
ya numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .page 237
data(PortraitStudio) ## maybe str(PortraitStudio) ; plot(PortraitStudio) ...data(PortraitStudio) ## maybe str(PortraitStudio) ; plot(PortraitStudio) ...
Premium Distribution
data("PremiumDistribution")data("PremiumDistribution")
A data frame with 100 observations on the following 3 variables.
ya numeric vector
groupa numeric vector
numa numeric vector
data(PremiumDistribution) ## maybe str(PremiumDistribution) ; plot(PremiumDistribution) ...data(PremiumDistribution) ## maybe str(PremiumDistribution) ; plot(PremiumDistribution) ...
prediction sum of squares
pressc(fit)pressc(fit)
fit |
model of regression |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .page 360
######## example page 361 pressc(lm(lny~x2+x3+x4,SurgicalUnit))######## example page 361 pressc(lm(lny~x2+x3+x4,SurgicalUnit))
Productivity Improvement dataset
data("ProductivityImprovement")data("ProductivityImprovement")
A data frame with 27 observations on the following 4 variables.
yresponse variable
groupfactor variable
numindex corresponding to each response
xcovariate
data(ProductivityImprovement) ## maybe str(ProductivityImprovement) ; plot(ProductivityImprovement) ...data(ProductivityImprovement) ## maybe str(ProductivityImprovement) ; plot(ProductivityImprovement) ...
Programmer Requirements dataset
data("ProgrammerRequirements")data("ProgrammerRequirements")
A data frame with 24 observations on the following 4 variables.
yresponse variable
Afactor A variable
Bfactor B variable
rowindex corresponding to each response
data(ProgrammerRequirements) ## maybe str(ProgrammerRequirements) ; plot(ProgrammerRequirements) ...data(ProgrammerRequirements) ## maybe str(ProgrammerRequirements) ; plot(ProgrammerRequirements) ...
Questionnaire Color
data("QuestionnaireColor")data("QuestionnaireColor")
A data frame with 15 observations on the following 3 variables.
ya numeric vector
groupa numeric vector
numa numeric vector
data(QuestionnaireColor) ## maybe str(QuestionnaireColor) ; plot(QuestionnaireColor) ...data(QuestionnaireColor) ## maybe str(QuestionnaireColor) ; plot(QuestionnaireColor) ...
Rehabilitation Therapy
data("RehabilitationTherapy")data("RehabilitationTherapy")
A data frame with 24 observations on the following 3 variables.
ya numeric vector
groupa numeric vector
numa numeric vector
data(RehabilitationTherapy) ## maybe str(RehabilitationTherapy) ; plot(RehabilitationTherapy) ...data(RehabilitationTherapy) ## maybe str(RehabilitationTherapy) ; plot(RehabilitationTherapy) ...
Risk Premium
data("RiskPremium")data("RiskPremium")
A data frame with 15 observations on the following 3 variables.
ya numeric vector
blocka numeric vector
factora numeric vector
data(RiskPremium) ## maybe str(RiskPremium) ; plot(RiskPremium) ...data(RiskPremium) ## maybe str(RiskPremium) ; plot(RiskPremium) ...
RoadPaintWear
data("RoadPaintWear")data("RoadPaintWear")
A data frame with 40 observations on the following 3 variables.
ya numeric vector
locationa numeric vector
painta numeric vector
data(RoadPaintWear) ## maybe str(RoadPaintWear) ; plot(RoadPaintWear) ...data(RoadPaintWear) ## maybe str(RoadPaintWear) ; plot(RoadPaintWear) ...
RustIn hibitor dataset
data("RustInhibitor")data("RustInhibitor")
A data frame with 40 observations on the following 3 variables.
yresponse variable
groupfactor variable
rowindex corresponding to each response
data(RustInhibitor) ## maybe str(RustInhibitor) ; plot(RustInhibitor) ...data(RustInhibitor) ## maybe str(RustInhibitor) ; plot(RustInhibitor) ...
Salable Flowers
data("SalableFlowers")data("SalableFlowers")
A data frame with 24 observations on the following 5 variables.
ya numeric vector
xa numeric vector
Aa numeric vector
Ba numeric vector
numa numeric vector
data(SalableFlowers) ## maybe str(SalableFlowers) ; plot(SalableFlowers) ...data(SalableFlowers) ## maybe str(SalableFlowers) ; plot(SalableFlowers) ...
satterthwaite
satterthwaite(c, MSE, df, alpha = 0.05)satterthwaite(c, MSE, df, alpha = 0.05)
c |
c |
MSE |
mse |
df |
df |
alpha |
a |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. chapter 25.
##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (c, MSE, df, alpha = 0.05) { l = c * MSE L = sum(c * MSE) dff <- ((L^2)/sum((l^2)/df)) lower <- (dff * L)/(qchisq(1 - alpha/2, round(dff))) upper <- (dff * L)/(qchisq(alpha/2, round(dff))) return(cbind(estimate = L, df = round(dff), lower = lower, upper = upper)) }##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (c, MSE, df, alpha = 0.05) { l = c * MSE L = sum(c * MSE) dff <- ((L^2)/sum((l^2)/df)) lower <- (dff * L)/(qchisq(1 - alpha/2, round(dff))) upper <- (dff * L)/(qchisq(alpha/2, round(dff))) return(cbind(estimate = L, df = round(dff), lower = lower, upper = upper)) }
Schwarz' Bayesian criterion
SBCp(model)SBCp(model)
model |
model of regression |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .page 360
##################use data Surgical Unit, page 360 SBCp(lm(lny~x4,SurgicalUnit))##################use data Surgical Unit, page 360 SBCp(lm(lny~x4,SurgicalUnit))
Servo Data dataset
data("ServoData")data("ServoData")
A data frame with 15 observations on the following 3 variables.
yresponse variable
groupfactor variable
rowindex corresponding to each response
data(ServoData) ## maybe str(ServoData) ; plot(ServoData) ...data(ServoData) ## maybe str(ServoData) ; plot(ServoData) ...
Solution Concentration
data("SolutionConcentration")data("SolutionConcentration")
A data frame with 15 observations on the following 2 variables.
ya numeric vector
xa numeric vector
data(SolutionConcentration) ## maybe str(SolutionConcentration) ; plot(SolutionConcentration) ...data(SolutionConcentration) ## maybe str(SolutionConcentration) ; plot(SolutionConcentration) ...
This approach is to specify the major comparisons of interest. Determine the expected widths of the confidence intervals for various sample sizes, given standard deviation (sigma).
ssea.oneway(number.group,mc,sigma,n.weight,ci.width,type=c("s", "b"), alpha = 0.05)ssea.oneway(number.group,mc,sigma,n.weight,ci.width,type=c("s", "b"), alpha = 0.05)
number.group |
number of treatments. |
mc |
matrix of contrast. each row determine one contrast. |
sigma |
Standard deviation. |
n.weight |
weight of sample size Corresponding to each treatment. |
ci.width |
width of confidence interval Corresponding to each contrast. |
type |
type of calculate confidence interval. |
alpha |
Confidence interval calculate with 1-alpha percent |
sample size obtain based on confidence interval.
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. page 759.
mc=matrix(c(1,-1,0,0,.5,.5,-.5,-.5,1/3,1/3,1/3,-1),byrow=TRUE,nrow = 3) ssea.oneway(4,mc,sigma=2,n.weight=c(1,1,1,1),ci.width=c(2.61,1.85,2.14)*2,type='s') #### page 761 mc=matrix( c(1,0,0,-1,0,1,0,-1,0,0,1,-1),byrow=TRUE,nrow = 3) ssea.oneway(4,mc,2,n.weight=c(1,1,1,2),ci.width=c(1,1,1)*2,type='b',alpha=.1) #### problem 17.25 page 772 mc=matrix(c(1,-1,0,0,0,0, .5,.5,-.5,-.5,0,0, 0,0,1,-1,0,0, .25,.25,.25,.25,-.5,-.5),byrow=TRUE,nrow=4) ssea.oneway(6,mc,.15,n.weight=rep(1,6),ci.width=rep(2*0.08,4),type='b',alpha=.05)mc=matrix(c(1,-1,0,0,.5,.5,-.5,-.5,1/3,1/3,1/3,-1),byrow=TRUE,nrow = 3) ssea.oneway(4,mc,sigma=2,n.weight=c(1,1,1,1),ci.width=c(2.61,1.85,2.14)*2,type='s') #### page 761 mc=matrix( c(1,0,0,-1,0,1,0,-1,0,0,1,-1),byrow=TRUE,nrow = 3) ssea.oneway(4,mc,2,n.weight=c(1,1,1,2),ci.width=c(1,1,1)*2,type='b',alpha=.1) #### problem 17.25 page 772 mc=matrix(c(1,-1,0,0,0,0, .5,.5,-.5,-.5,0,0, 0,0,1,-1,0,0, .25,.25,.25,.25,-.5,-.5),byrow=TRUE,nrow=4) ssea.oneway(6,mc,.15,n.weight=rep(1,6),ci.width=rep(2*0.08,4),type='b',alpha=.05)
A hospital surgical unit was interested in predicting survival in patients undergoing a particular of type of liver operation.
data("SurgicalUnit")data("SurgicalUnit")
A data frame with 54 observations on the following 10 variables.
x1a numeric vector
x2a numeric vector
x3a numeric vector
x4a numeric vector
x5a numeric vector
x6a numeric vector
x7a numeric vector
x8a numeric vector
ya numeric vector
lnya numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .page 350
data(SurgicalUnit) ## maybe str(SurgicalUnit) ; plot(SurgicalUnit) ...data(SurgicalUnit) ## maybe str(SurgicalUnit) ; plot(SurgicalUnit) ...
54 additional data for SurgicalUnit dataset.
data("SurgicalUnitAdditional")data("SurgicalUnitAdditional")
A data frame with 54 observations on the following 10 variables.
x1a numeric vector
x2a numeric vector
x3a numeric vector
x4a numeric vector
x5a numeric vector
x6a numeric vector
x7a numeric vector
x8a numeric vector
ya numeric vector
lnya numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .TABLE 9.5 page 374
data(SurgicalUnitAdditional) ## maybe str(SurgicalUnitAdditional) ; plot(SurgicalUnitAdditional) ...data(SurgicalUnitAdditional) ## maybe str(SurgicalUnitAdditional) ; plot(SurgicalUnitAdditional) ...
Task Completion
data("TaskCompletion")data("TaskCompletion")
A data frame with 16 observations on the following 4 variables.
ya numeric vector
blocka numeric vector
factora numeric vector
numa numeric vector
data(TaskCompletion) ## maybe str(TaskCompletion) ; plot(TaskCompletion) ...data(TaskCompletion) ## maybe str(TaskCompletion) ; plot(TaskCompletion) ...
Telephone Communications datas set
data("TelephoneCommunications")data("TelephoneCommunications")
A data frame with 30 observations on the following 3 variables.
ya numeric vector
groupa numeric vector
numa numeric vector
data(TelephoneCommunications) ## maybe str(TelephoneCommunications) ; plot(TelephoneCommunications) ...data(TelephoneCommunications) ## maybe str(TelephoneCommunications) ; plot(TelephoneCommunications) ...
The Toluca Company manufactures refrigeration equipment as well as many replacement parts. In the past, one of the replacement parts has been produced periodically in lots of varying sizes. When a cost improvement program was undertaken, company officials wished to determine the optimum lot size for producing this part.
data("TolucaCompany")data("TolucaCompany")
A data frame with 25 observations on the following 2 variables.
xa numeric vector
ya numeric vector
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition .page 19
data(TolucaCompany) ## maybe str(TolucaCompany) ; plot(TolucaCompany) ...data(TolucaCompany) ## maybe str(TolucaCompany) ; plot(TolucaCompany) ...
Confidence intervals for tow way ANOVA.
Estimation and confidense interval of Factor Level Mean.
Estimation and confidense interval of Contrast of Factor Level Means
Estimation and confidense interval of linear Combination of Factor level Means
Multiple Pairwise Comparisons and confidense interval of Factor level Means (Tukey and Bonferroni Procedurs)
Multiple Contrasts and confidense interval of Factor Level Means (scheffe and Bonferroni Procedurs)
Etimates and confidense interval Based on Treatment Means
Interactions Are Important:
Multiple Pairwise Comparisons of Treatment Means(Tukey and Bonferroni Procedure.)
Multiple Contrasts of Treatment Means(Scheffe and Bonferroni Procedure.)
towway.ci(y, x1, x2, mc = NULL, mp = NULL,mt=NULL, mse= NULL,alpha = 0.05)towway.ci(y, x1, x2, mc = NULL, mp = NULL,mt=NULL, mse= NULL,alpha = 0.05)
y |
response variabel |
x1 |
first factor |
x2 |
second factor |
mc |
matrix of contrast(s) |
mp |
matrix of pairwise. each row is one pairwise |
mt |
matrix of treatment means. (interaction NOT important) |
mse |
MSE of model |
alpha |
Confidence intervals calculate with 1-alpha percent |
Michael H. Kutner; Christopher J. Nachtsheim; John Neter; William Li. Applied Linear Statistical Models Fifth Edition. chapter 19.
library('ALSM') y=HayFeverRelief$y A=HayFeverRelief$A B=HayFeverRelief$B m=matrix(c(1,2,3,0,0,0,.5,-1,.5),byrow = TRUE,nrow = 3) towway.ci(y,A,B,mc=m)library('ALSM') y=HayFeverRelief$y A=HayFeverRelief$A B=HayFeverRelief$B m=matrix(c(1,2,3,0,0,0,.5,-1,.5),byrow = TRUE,nrow = 3) towway.ci(y,A,B,mc=m)
In a completely randomized design to study the effect of the speed of winding thread (1: slow; 2: normal; 3: fast; 4: maximum) onto 75-yard spools, 16 runs of 10,000 spools each were made at each of the four winding speeds. The response variable is the number of thread breaks during, the production run.
data("WindingSpeeds")data("WindingSpeeds")
A data frame with 64 observations on the following 3 variables.
yresponse variable
groupfactor variable
rowindex corresponding to each response
data(WindingSpeeds) ## maybe str(WindingSpeeds) ; plot(WindingSpeeds) ...data(WindingSpeeds) ## maybe str(WindingSpeeds) ; plot(WindingSpeeds) ...