Zhiguang Huo (Caleb)
Wednesday September 16, 2020
## [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
## [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
set.seed(32611)
curve(dnorm,-4,4, ylim = c(-0.1, 0.5))
# shaded area
xvals <- seq(-4,2,length=100)
dvals <- dnorm(xvals)
polygon(c(xvals,rev(xvals)),c(rep(0,100),rev(dvals)),col="gray")
#label pnorm as area under the curve
arrows(1,.15,2,.25,code=1,angle=30,length=.1,lwd=2)
text(2,.25,paste('pnorm(2) =',round(pnorm(2),3)),cex=.75,pos=3)
#label dnorm as height
segments(2,0,2,dnorm(2),lwd=2,col=2)
arrows(2,.025,2.5,.1, code=1, angle=30, length=.1, lwd=2, col=2)
text(2.5,.1,paste('dnorm(2) =', round(dnorm(2),3)), cex=.75, pos=3, col=2)
#label qnorm as quantile
points(2,0,col=4,pch=16,cex=1.1)
arrows(2,0,3,.05,code=1,angle=30,length=.1,lwd=2,col=4)
text(3,.05,paste('qnorm(',round(pnorm(2),3),') = 2'), cex=.75,pos=3,col=4)
mtext(side=3,line=.5,'X ~ Normal(0,1)',cex=.9,font=2)
points(rnorm(20),jitter(rep(0,20)),pch=18,cex=.9)
legend(-4,.3,'rnorm(20)',pch=18,cex=.8,bty='n')
n <- 80
set.seed(32611)
x <- sort(runif(n, min = 0, max=2*pi))
y <- sin(x) + rnorm(n, mean = 0, sd = 0.2)
pdf("sinFunction.pdf")
plot(x,y)
dev.off()
## quartz_off_screen
## 2
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
## [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
par(mfrow = c(2,2))
xlims <- range(iris$Petal.Length) ## set common x limits
uniqueSpecies <- levels(iris$Species)
for(i in seq_along(uniqueSpecies)){
aspecies <- uniqueSpecies[i]
sampleSelection <- iris$Species==aspecies
adata <- iris$Petal.Length[sampleSelection]
hist(adata, col=i, xlim=xlims, xlab="petal length",main=aspecies)
}
B=16
greenRed <- rgb(c(rep(0, B), (0:B)/B), c((B:0)/16, rep(0, B)), rep(0, 2*B+1))
species <- iris$Species
levels(species) <- 1:3
rowColor <- palette()[species]
heatmap(matrix, col= greenRed, margin=c(7,7),
Rowv = NA, Colv = NA, RowSideColors = rowColor)
legend("topright",legend = levels(iris$Species),fill=levels(species))
B=16
greenRed <- rgb(c(rep(0, B), (0:B)/B), c((B:0)/16, rep(0, B)), rep(0, 2*B+1))
species <- iris$Species
levels(species) <- 1:3
rowColor <- palette()[species]
heatmap(matrix, col= greenRed, margin=c(7,7),
Rowv = NA, Colv = NA,
RowSideColors = rowColor,
labRow = "", labCol = "", main="heatmap of iris data")
legend("topright",legend = levels(iris$Species),fill=levels(species))