Docsity

Lecture Notes on Univariate Data Visualization | STAT 6560, Study notes of Statistics

Toggle sidebar
bg1
R02 - Univariate Data Visualization
> library(lattice)
>
> library(MASS) # For cereal data
> data(UScereal)
> head(UScereal)
mfr calories protein fat sodium fibre
100% Bran N 212.1212 12.121212 3.030303 393.9394 30.303030
All-Bran K 212.1212 12.121212 3.030303 787.8788 27.272727
All-Bran with Extra Fiber K 100.0000 8.000000 0.000000 280.0000 28.000000
carbo sugars shelf potassium vitamins
100% Bran 15.15152 18.18182 3 848.48485 enriched
All-Bran 21.21212 15.15152 3 969.69697 enriched
All-Bran with Extra Fiber 16.00000 0.00000 3 660.00000 enriched
>
> Kel.carbs <- UScereal[UScereal$mfr=="K",7]
> Kel.carbs
[1] 21.21212 16.00000 11.00000 21.00000 13.00000 20.00000 21.00000 11.00000
[9] 18.66667 17.50000 20.89552 26.66667 25.37313 22.38806 31.34328 20.00000
[17] 18.66667 30.00000 22.00000 12.00000 16.00000
> names(Kel.carbs) <- row.names(UScereal[UScereal$mfr=="K",])
> Kel.carbs
All-Bran All-Bran with Extra Fiber Apple Jacks
21.21212 16.00000 11.00000
Corn Flakes Corn Pops Cracklin' Oat Bran
21.00000 13.00000 20.00000
Crispix Froot Loops Frosted Flakes
21.00000 11.00000 18.66667
Frosted Mini-Wheats Fruitful Bran Just Right Fruit & Nut
17.50000 20.89552 26.66667
Mueslix Crispy Blend Nut&Honey Crunch Nutri-Grain Almond-Raisin
25.37313 22.38806 31.34328
Product 19 Raisin Bran Raisin Squares
20.00000 18.66667 30.00000
Rice Krispies Smacks Special K
22.00000 12.00000 16.00000
>
> dotchart(Kel.carbs)
> dotchart(sort(Kel.carbs))
> dotchart(sort(Kel.carbs), xlim=c(10,35), xlab="g carbohydrates per 1 cup
serving")
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Lecture Notes on Univariate Data Visualization | STAT 6560 and more Study notes Statistics in PDF only on Docsity!

R02 - Univariate Data Visualization

library(lattice)

library(MASS) # For cereal data data(UScereal) head(UScereal) mfr calories protein fat sodium fibre 100% Bran N 212.1212 12.121212 3.030303 393.9394 30. All-Bran K 212.1212 12.121212 3.030303 787.8788 27. All-Bran with Extra Fiber K 100.0000 8.000000 0.000000 280.0000 28. carbo sugars shelf potassium vitamins 100% Bran 15.15152 18.18182 3 848.48485 enriched All-Bran 21.21212 15.15152 3 969.69697 enriched All-Bran with Extra Fiber 16.00000 0.00000 3 660.00000 enriched

Kel.carbs <- UScereal[UScereal$mfr=="K",7] Kel.carbs [1] 21.21212 16.00000 11.00000 21.00000 13.00000 20.00000 21.00000 11. [9] 18.66667 17.50000 20.89552 26.66667 25.37313 22.38806 31.34328 20. [17] 18.66667 30.00000 22.00000 12.00000 16. names(Kel.carbs) <- row.names(UScereal[UScereal$mfr=="K",]) Kel.carbs All-Bran All-Bran with Extra Fiber Apple Jacks 21.21212 16.00000 11. Corn Flakes Corn Pops Cracklin' Oat Bran 21.00000 13.00000 20. Crispix Froot Loops Frosted Flakes 21.00000 11.00000 18. Frosted Mini-Wheats Fruitful Bran Just Right Fruit & Nut 17.50000 20.89552 26. Mueslix Crispy Blend Nut&Honey Crunch Nutri-Grain Almond-Raisin 25.37313 22.38806 31. Product 19 Raisin Bran Raisin Squares 20.00000 18.66667 30. Rice Krispies Smacks Special K 22.00000 12.00000 16.

dotchart(Kel.carbs) dotchart(sort(Kel.carbs)) dotchart(sort(Kel.carbs), xlim=c(10,35), xlab="g carbohydrates per 1 cup serving")

dotplot(Kel.carbs) # from lattice library dotplot(sort(Kel.carbs), xlim=c(10,35), xlab="g carbohydrates per 1 cup serving") data(state) dotchart(state.area) dotchart(sort(state.area), labels= state.name[order(state.area)], cex=.7) dotchart(log10(sort(state.area)), labels= state.name[order(state.area)], cex=.7)

stripplot(plength,jitter=T) stripplot(plength,jitter=T,factor=5) n<-length(plength) plot(((1:n)-.5)/n,sort(plength))

qqmath(~plength,dist=qunif) #lattice qqnorm(plength) qqmath(~plength,dist=qnorm) plot(ecdf(plength))

boxplot(plength) hist(plength) hist(plength,breaks="Scott",freq=F) hist(plength,breaks="FD",freq=F) h<-3.5sd(plength)n^(-1/3) h [1] 1. range(plength) [1] 1.0 6. tk<-seq(.9,8,by=h) tk [1] 0.900000 2.062846 3.225693 4.388539 5.551386 6.714232 7. hist(plength,breaks=tk,freq=F)

tk<-seq(.9,8,by=h/2) hist(plength,breaks=tk,freq=F) histogram(~plength,type="density",breaks=tk) #lattice

plot(density(plength,adjust=1/2)) plot(density(plength,adjust=1/4)) plot(density(plength,adjust=2)) plot(density(0, bw=1, kernel="g"))# Examine individual kernels, h = 1 plot(density(chondrite, bw=1, kernel="g")) # gaussian kernel (default) plot(density(0, bw=1, kernel="e"))# epanechnikov

plot(density(chondrite, bw=1, kernel="e")) plot(density(0, bw=1, kernel="b"))# biweight plot(density(chondrite, bw=1, kernel="b")) plot(density(0, bw=1, kernel="o"))# optcosine (cosine arch) plot(density(chondrite, bw=1, kernel="o")) plot(density(0, bw=1, kernel="c"))# cosine

plot(density(plength,bw="nrd")) # normal reference rule bw plot(density(plength,bw="SJ")) # Sheather-Jones bw densityplot(plength) # lattice, takes all parameters from density (above) densityplot(plength,n=512) densityplot(plength,n=512,bw="SJ") plot(density(chondrite,"nrd")) plot(density(chondrite,"SJ"))