data(anscombe)
anscombe
## x1 x2 x3 x4 y1 y2 y3 y4
## 1 10 10 10 8 8.04 9.14 7.46 6.58
## 2 8 8 8 8 6.95 8.14 6.77 5.76
## 3 13 13 13 8 7.58 8.74 12.74 7.71
## 4 9 9 9 8 8.81 8.77 7.11 8.84
## 5 11 11 11 8 8.33 9.26 7.81 8.47
## 6 14 14 14 8 9.96 8.10 8.84 7.04
## 7 6 6 6 8 7.24 6.13 6.08 5.25
## 8 4 4 4 19 4.26 3.10 5.39 12.50
## 9 12 12 12 8 10.84 9.13 8.15 5.56
## 10 7 7 7 8 4.82 7.26 6.42 7.91
## 11 5 5 5 8 5.68 4.74 5.73 6.89
plot(anscombe$y1 ~ anscombe$x1)

# Fit the regression model.
data.1 <- lm(y1~x1, data = anscombe)
# Scatterplot of the data.
plot(anscombe$y1 ~ anscombe$x1,
ylab = expression(italic(Y)),
ylim = c(2, 12),
xlab = expression(italic(X)),
main = "Anscombe's Data Set 1")
# Add the fitted regression line.
abline(data.1)
# Add the text and expressions within the figure.
text(5.9, 9.35,expression(paste("The value of ", italic(R)^2, " is.67", sep = "")))
text(5.9, 10.15, expression(italic(hat(Y)) == 3+italic(X)*.5))
# Break the axis by adding a zigzag.
require(plotrix)
## Loading required package: plotrix
axis.break(axis = 1, style = "zigzag")
axis.break(axis = 2, style = "zigzag")

Cassidy <- read.csv("Cassady.csv")
pairs(cbind(GPA = Cassidy$GPA, CTA_Total = Cassidy$CTA.tot, BS_Total = Cassidy$BStotal))
cor(na.omit(cbind(GPA = Cassidy$GPA, CTA_Total = Cassidy$CTA.tot,BS_Total = Cassidy$BStotal)))
## GPA CTA_Total BS_Total
## GPA 1.0000000 -0.3031156 -0.1293748
## CTA_Total -0.3031156 1.0000000 0.7093240
## BS_Total -0.1293748 0.7093240 1.0000000
Achieve <- read.csv("Achieve.csv")
library(lattice)

dotplot(
class ~ geread,
data = Achieve, jitter.y = TRUE, ylab = "Classroom")

Achieve.940.767 <- Achieve[Achieve$corp == 940 & Achieve$school == 767,]
dotplot(
class ~ geread,
data = Achieve.940.767, jitter.y = TRUE, ylab = "Classroom",
main = "Dotplot of \'geread\' for Classrooms in School 767, Which is Within Corporation 940")

dotplot(
reorder(class, geread) ~ geread,
data = Achieve.940.767, jitter.y = TRUE, ylab = "Classroom",
main = "Dotplot of \'geread\' for Classrooms in School 767, Which is Within Corporation 940")

dotplot(reorder(corp, geread) ~ geread, data = Achieve,
jitter.y = TRUE,
ylab = "Classroom", main = "Dotplot of \'geread\' for All Corporations")

Achieve <- cbind(Achieve, Classroom_Unique =
paste(Achieve$corp, Achieve$school, Achieve$class, sep = ""))
xyplot(geread ~ gevocab | corp, data = Achieve)

xyplot(geread ~ gevocab | school, data = Achieve[Achieve$corp == 940,],
strip = strip.custom(strip.names = FALSE,
strip.levels = c(FALSE, TRUE)), main = "Schools in Corporation 940")

library(nlme)
library(MASS)
mathfinal <- read.csv("MathFinal.csv")
summary(model8.1<-glmmPQL(score2~Salary,random = ~1|school, family = binomial, data = mathfinal))
## iteration 1
## iteration 2
## iteration 3
## iteration 4
## Linear mixed-effects model fit by maximum likelihood
## Data: mathfinal
## AIC BIC logLik
## NA NA NA
##
## Random effects:
## Formula: ~1 | school
## (Intercept) Residual
## StdDev: 0.4934744 0.9969691
##
## Variance function:
## Structure: fixed weights
## Formula: ~invwt
## Fixed effects: score2 ~ Salary
## Value Std.Error DF t-value p-value
## (Intercept) 0.6305205 0.3556496 6782 1.7728698 0.0763
## Salary -0.0000078 0.0000094 30 -0.8369916 0.4092
## Correlation:
## (Intr)
## Salary -0.966
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -2.1309160 -1.0463880 0.6415727 0.8300013 1.4503588
##
## Number of Observations: 6814
## Number of Groups: 32
summary(model8.2<-glmmPQL(score2~Salary,random = ~Salary|school,family = binomial, data = mathfinal))
## iteration 1
## iteration 2
## iteration 3
## iteration 4
## Linear mixed-effects model fit by maximum likelihood
## Data: mathfinal
## AIC BIC logLik
## NA NA NA
##
## Random effects:
## Formula: ~Salary | school
## Structure: General positive-definite, Log-Cholesky parametrization
## StdDev Corr
## (Intercept) 4.934748e-01 (Intr)
## Salary 2.367619e-08 0
## Residual 9.969691e-01
##
## Variance function:
## Structure: fixed weights
## Formula: ~invwt
## Fixed effects: score2 ~ Salary
## Value Std.Error DF t-value p-value
## (Intercept) 0.6305204 0.3556504 6782 1.772866 0.0763
## Salary -0.0000078 0.0000094 30 -0.836989 0.4092
## Correlation:
## (Intr)
## Salary -0.966
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -2.1309167 -1.0463880 0.6415726 0.8300013 1.4503593
##
## Number of Observations: 6814
## Number of Groups: 32