x <- rnorm(50)
mean(x)
sd(x)
var(x)
median(x)
quantile(x)
pvec <- seq(0,1,0.1)
pvec
quantile(x,pvec)
attach(juul)
 mean(igf1)
mean(igf1,na.rm=T)
sum(!is.na(igf1))
summary(igf1)
summary(juul)
detach(juul)
juul$sex <- factor(juul$sex,labels=c("M","F"))            
juul$menarche <- factor(juul$menarche,labels=c("No","Yes"))
juul$tanner <- factor(juul$tanner,
                      labels=c("I","II","III","IV","V"))
attach(juul)
summary(juul)
hist(x)
if (.make.epsf) dev.copy2eps(file="hist.ps")
mid.age <- c(2.5,7.5,13,16.5,17.5,19,22.5,44.5,70.5)
acc.count <- c(28,46,58,20,31,64,149,316,103)
age.acc <- rep(mid.age,acc.count)
brk <- c(0,5,10,16,17,18,20,25,60,80)
hist(age.acc,breaks=brk)
if (.make.epsf) dev.copy2eps(file="hist-acc-right.ps")
n <- length(x)
plot(sort(x),(1:n)/n,type="s",ylim=c(0,1))
if (.make.epsf) dev.copy2eps(file="empdist.ps")
qqnorm(x)
if (.make.epsf) dev.copy2eps(file="qqnorm.ps")
par(mfrow=c(1,2))
boxplot(IgM)
boxplot(log(IgM))
par(mfrow=c(1,1))
if (.make.epsf) dev.copy2eps(file="boxplot-IgM.ps")
attach(red.cell.folate)
tapply(folate,ventilation,mean)
tapply(folate,ventilation,sd)
tapply(folate,ventilation,length)
xbar <- tapply(folate, ventilation, mean)
s <- tapply(folate, ventilation, sd)
n <- tapply(folate, ventilation, length)
cbind(mean=xbar, std.dev=s, n=n)
tapply(igf1, tanner, mean)
tapply(igf1, tanner, mean, na.rm=T)
aggregate(juul[c("age","igf1")], 
          list(sex=juul$sex), mean, na.rm=T)
aggregate(juul[c("age","igf1")], juul["sex"], mean, na.rm=T)
by(juul, juul["sex"], summary)
attach(energy)
expend.lean <- expend[stature=="lean"]
expend.obese <- expend[stature=="obese"]
par(mfrow=c(2,1))
hist(expend.lean,breaks=10,xlim=c(5,13),ylim=c(0,4),col="white")
hist(expend.obese,breaks=10,xlim=c(5,13),ylim=c(0,4),col="grey")
par(mfrow=c(1,1))
if (.make.epsf) dev.copy2eps(file="expend-hist-2on1.ps")
boxplot(expend ~ stature)
if (.make.epsf) dev.copy2eps(file="boxplots-expend-stat.ps")
boxplot(expend.lean,expend.obese)
opar <- par(mfrow=c(2,2), mex=0.8, mar=c(3,3,2,1)+.1)
stripchart(expend ~ stature)
stripchart(expend ~ stature, method="stack")
stripchart(expend ~ stature, method="jitter")
stripchart(expend ~ stature, method="jitter", jitter=.03)
par(opar)
if (.make.epsf) dev.copy2eps(file="stripcharts-expend-stat.ps")
caff.marital <- matrix(c(652,1537,598,242,36,46,38,21,218
,327,106,67),
nrow=3,byrow=T)
caff.marital
colnames(caff.marital) <- c("0","1-150","151-300",">300")
rownames(caff.marital) <- c("Married","Prev.married","Single")
caff.marital
names(dimnames(caff.marital)) <- c("marital","consumption")
caff.marital
as.data.frame(as.table(caff.marital))
table(sex)
table(sex,menarche)
table(menarche,tanner)
xtabs(~ tanner + sex, data=juul)
xtabs(~ dgn + diab + coma, data=stroke)
ftable(coma + diab ~ dgn, data=stroke)
t(caff.marital)
tanner.sex <- table(tanner,sex)
tanner.sex
margin.table(tanner.sex,1)
margin.table(tanner.sex,2)
prop.table(tanner.sex,1)
tanner.sex/sum(tanner.sex)
total.caff <- margin.table(caff.marital,2) 
total.caff
barplot(total.caff, col="white")
if (.make.epsf) dev.copy2eps(file="simple-bar.ps")
par(mfrow=c(2,2))
barplot(caff.marital, col="white")
barplot(t(caff.marital), col="white")
barplot(t(caff.marital), col="white", beside=T)
barplot(prop.table(t(caff.marital),2), col="white", beside=T)
par(mfrow=c(1,1))
if (.make.epsf) dev.copy2eps(file="mat-4-bar.ps")
barplot(prop.table(t(caff.marital),2),beside=T, 
legend.text=colnames(caff.marital),
col=c("white","grey80","grey50","black"))
if (.make.epsf) dev.copy2eps(file="pretty-bar.ps")
dotchart(t(caff.marital), lcolor="black")
if (.make.epsf) dev.copy2eps(file="dotchart.ps")
opar <- par(mfrow=c(2,2),mex=0.8, mar=c(1,1,2,1))
slices <- c("white","grey80","grey50","black")
pie(caff.marital["Married",], main="Married", col=slices)
pie(caff.marital["Prev.married",],
         main="Previously married", col=slices)
pie(caff.marital["Single",], main="Single", col=slices)
par(opar)
if (.make.epsf) dev.copy2eps(file="pie.ps")
rm(list=ls())
while(search()[2] != "package:ISwR") detach()
