5주
From Biocourse
boacelgetcr## ìë£ë¥¼ ë¶í íì¬ ííí 그림.
> library(MASS) ## MASSë¼ë library를 ë¶ë¬ì¨ë¤.
> data(geyser) ## geyserë¼ë ìë£ë¥¼ ë¶ë¬ì¨ë¤.
> attach(geyser) ## geyser ìë£ë¥¼ ë³ìë³ë¡ íì±í ìí¨ë¤.
> plot(waiting,duration,type="n",ylab="Eruption Length",xlab="Waiting Time for the Eruption")
## geyser ë³ìì¸ waitingê³¼ durationì ì´ì©íì¬ ê·¸ë¦¼ì 그린ë¤.
## type="n"ìµì
ì ìë£ì ê·¸ë¦¬ì§ ë§ë¼ë ìµì
ì´ë¤.
## yì¶ ë 벨ì Eruption Lengthë¡, xì¶ ë 벨ì Waiting Time for the Eruption ì¼ë¡ ëíë¸ë¤.
> title("Old Faithful Ceyser Data \n Waiting Time and Eruption Length") ## 그림ì íì´íì ì
ë ¥íë¤.
> abline(h=3.1) ## yê°ì´ 3.1ì ìíì ì 그린ë¤.
> abline(v=67) ## xê° 67ì ìì§ì ì 그린ë¤.
> subset1<-(waiting<67)&(duration<3.1)
## waitingê³¼ durationì ë¤ì ì¡°ê±´ì ë§ì¡±ì¬ë¶ë¥¼ subset1ì ë
¼ë¦¬ìë£ ì
ë ¥íë¤.
> subset2<-(waiting<67)&(duration>3.1)
## waitingê³¼ durationì ë¤ì ì¡°ê±´ì ë§ì¡±ì¬ë¶ë¥¼ subset2ì ë
¼ë¦¬ìë£ ì
ë ¥íë¤.
> subset3<-(waiting>67)&(duration<3.1)
## waitingê³¼ durationì ë¤ì ì¡°ê±´ì ë§ì¡±ì¬ë¶ë¥¼ subset3ì ë
¼ë¦¬ìë£ ì
ë ¥íë¤.
> subset4<-(waiting>67)&(duration>3.1)
## waitingê³¼ durationì ë¤ì ì¡°ê±´ì ë§ì¡±ì¬ë¶ë¥¼ subset4ì ë
¼ë¦¬ìë£ ì
ë ¥íë¤.
> points(waiting[subset1],duration[subset1],pch="A",col=1)
## waitingê³¼ durationìì subset1ì ë§ì¡±ë ê°ë§ Aë¡ ê·¸ë¦¼ì 그린ë¤.
> points(waiting[subset2],duration[subset2],pch="B",col=2)
## waitingê³¼ durationìì subset2ì ë§ì¡±ë ê°ë§ Aë¡ ê·¸ë¦¼ì 그린ë¤.
> points(waiting[subset3],duration[subset3],pch="C",col=3)
## waitingê³¼ durationìì subset3ì ë§ì¡±ë ê°ë§ Aë¡ ê·¸ë¦¼ì 그린ë¤.
> points(waiting[subset4],duration[subset4],pch="D",col=4)
## waitingê³¼ durationìì subset4ì ë§ì¡±ë ê°ë§ Aë¡ ê·¸ë¦¼ì 그린ë¤.
> arrows(105,1,max(waiting),duration[waiting==max(waiting)],open=T)
## ê·¸ë¬ì§ ê°ì íì´í를 ê·¸ë ¤ ë£ëë¤.

## Të¶í¬ìì 기ê°ì 그림. ( ìë£ : barley.txt )
> barley = read.table("c://barley.txt",sep="\t",header=T) ## ìë£ë¥¼ C ëë í 리ìì ì½ì´ì barleyë¡ ì ì íë¤.
> attach(barley) ## barley ìë£ë¥¼ íì±í ìí¨ë¤.
> x<-yield[site=="Crookston"] ## site ê° Crookstonì¸ ìë£ì yieldê°ì xì ì ì¥
> y<-yield[site=="Morris"] ## site ê° Morrisì¸ ìë£ì yieldê°ì yì ì ì¥
> df<-length(x)-1 ## xì ê¸¸ì´ -1 ì dfì ì ì¥íë¤.
> alpha<-0.05 ## 0.05를 alphaì ì ì¥íë¤.
> bound.left<- -3 ## -3ì bound.leftì ì ì¥íë¤.
> bound.right<- 3 ## 3ì bound.rightì ì ì¥íë¤.
> xaxis<-seq(bound.left,bound.left,length=1000) ## bound.leftìì bound.leftê¹ì§ë¥¼ 1000ë±ë¶íë¤.
> yaxis<-dt(xaxis,df) ## xaxisì ê°ì t ë¶í¬ ìì ëê° dfì¸ density를 구íë¤.
> plot(xaxis,yaxis,type="l",xlab="",ylab="t density") ## xaxisì yaxisë¡ ê·¸ë¦¼ì 그린ë¤.
> critical.left<-qt(alpha/2,df)
## alpha/2를 të¶í¬ìì ìì ëê° dfì¸ qantile ê°ì 구íë¤.
> critical.right<-qt(1-alpha/2,df)
## 1 - alpha/2를 të¶í¬ìì ìì ëê° dfì¸ qantile ê°ì 구íë¤.
> xaxis<-seq(critical.left,critical.right,length=100)
## critical.leftìì critical.rightê¹ì§ë¥¼ 100ë±ë¶íë¤.
> yaxis<-c(dt(xaxis,df),0,0) ## yaxisì ê°ì ì ìíë¤.
> xaxis<-c(xaxis,critical.left,bound.left) ## xaxisì ê°ì ì ìíë¤.
> polygon(xaxis,yaxis,density=25)
## polygonì ì´ì©íì¬ ìë 그림 ì²ë¼ 구ê°ì ìì¼ë¡ ì±ì´ë¤.
> xaxis<-seq(critical.right,bound.right,length=100) ## critical.rightìì critical.rightê¹ì§ë¥¼ 100ë±ë¶íë¤.
> yaxis<-c(dt(xaxis,df),0,0) ## yaxisì ê°ì ì ìíë¤.
> xaxis<-c(xaxis,bound.right,critical.right) ## xaxisì ê°ì ì ìíë¤.
> polygon(xaxis,yaxis,density=25)
## polygonì ì´ì©íì¬ ìë 그림 ì²ë¼ 구ê°ì ìì¼ë¡ ì±ì´ë¤.
> test.stat<-t.test(x,y,paired=T,conf.level=1-alpha)$statistic
## t.test ì ìë£ ë¶ì ê²°ê³¼ìì ì ë¢°êµ¬ê° 1-alphaê°ì ì ì¥íë¤.
> points(test.stat,0.01,cex=1.5,pch="*") ## test.stat를 ì ì¼ë¡ íííë¤.
> text(test.stat,0.04,"paired test statistics",adj=1) ## 그림ì paired test statistics를 ì½ì
íë¤.
> test.stat<-t.test(x,y,paired=F,conf.level=1-alpha)$statistic
## t.test ë ìë£ ë¶ì ê²°ê³¼ìì ì ë¢°êµ¬ê° 1-alphaê°ì ì ì¥íë¤.
> points(test.stat,0.01,cex=1.5,pch="*") ## test.stat를 ì ì¼ë¡ íííë¤.
> text(test.stat,0.04,"unpaired",adj=0) ## 그림ì unpaired를 ì½ì
íë¤.
> text(bound.left, 0.08,"rejection \n region",adj=0) ## 그림ì rejection region를 ì½ì
íë¤.
> text(bound.right,0.08,"rejection \n region",adj=1) ## 그림ì rejection region를 ì½ì
íë¤.
> text((bound.left+bound.right)/2,0.16,"acceptance region") ## 그림ì acceptance region를 ì½ì
íë¤.
> xaxis<-c(rep(critical.left,2),rep(critical.right,2))
> yaxis<-c(0.12,0.14,0.14,0.12)
> lines(xaxis,yaxis)

> library(MASS) ## MASS library를 ë¶ë¥¸ë¤.
> data(geyser) ## geyserìë£ë¥¼ ë¶ë¥¸ë¤.
> frame() ## 그림ì 그릴ì ìë ì°½ì ë ì´ë¤.
> par(fig=c(0.0,0.7,0.0,0.7),mar=c(4,4,2,2),cex=0.7) ## ë ì´ ì°½ì íí°ì ì ëëë¤.
> plot(geyser$waiting,geyser$duration,pch="*",xlab="Waiting Time",ylab="Duration of Eruption")
## ëë íí°ì ì 그림ì 그린ë¤.
> title("\n Old Faithful Geyser Data Set",cex=0.5) ## íì´íì ë£ëë¤.
> par(new=T) ## ë ì´ ì°½ì ê·¸ëë¡ ì ì§í´ì 그림ì ì¶ê°íë¤.
> par(fig=c(0.0,0.7,0.7,1),mar=c(2,4,2,2),cex=0.7) ## ë ì´ ì°½ì íí°ì ì ëëë¤.
> hist(geyser$waiting) ## ëë íí°ì ì histogram그림ì 그린ë¤.
> par(new=T) ## ë ì´ ì°½ì ê·¸ëë¡ ì ì§í´ì 그림ì ì¶ê°íë¤.
> par(fig=c(0.7,1,0,1),mar=c(4,3,2,2),cex=0.7) ## ë ì´ ì°½ì íí°ì ì ëëë¤.
> boxplot(geyser$duration) ## ëë íí°ì ì boxplot그림ì 그린ë¤.
ë¤ë¥¸ ìì
> plot(x,sin(x)+cos(x),xlab="x values",ylab="y values",type="l")
> lines(x,sin(x),lty=3,col=3)
> lines(x,cos(x),lty=2,col=2)
> title("Trigonometric Functions","sin(x),cos(x),and sin(x)+cos(x)")
> z=seq(0,2*pi,length=1000)
> x=sin(z)
> y=cos(z)
> par(pin=c(2,2))
> plot(x,y,type="l",axes=F,xlab="",ylab="")
> title("A circle")
> z=seq(6*pi,32*pi,length=1000)
> x=sin(z)/(0.1*z)
> y=cos(z)/(0.1*z)
> plot(x,y,type="l",main="A spiral with 13 windings",axes=F,xlab="",ylab="")
> par(mfrow=c(2,2))
> x=seq(0,2*pi,length=1000)
> plot(sin(3*x),sin(6*x),type="l")
> plot(sin(3*x),sin(8*x),type="l")
> plot(sin(3*x),sin(11*x),type="l")
> plot(sin(7*x),sin(8*x),type="l")
