R-code 3

From Biocourse

Jump to: navigation, search
> x = c(0.05, 0.95)                                                                                ## 0.05, 0.95를 x에 할당한다.
> bounds.normal = qnorm(x)                                                            ## normal quantile를 이용하여 x의 정규분포 5%, 95%의 
                                                                                                           ## 값을 찾는다.
> bounds.t = qt(x,5)                                                                            ## t quantile을 이용하여 x의 t분포 자유도가 5인 5%, 95%의
                                                                                                          ## 값을 찾는다.  
> bounds.cauchy = qcauchy(x)                                                        ## cauchy quantile를 이용하여 cauchy분포의 5%, 95%의 
                                                                                                          ## 값을 찾는다.


> bounds = range ( bounds.normal, bounds.t, bounds.cauchy)   ## range를 이용하여bounds.normal, bounds.t, 
                                                                                                          ## bounds.cauchy의 가장 작은값 가장 큰값을 찾는다.
> points.x = seq( bounds[1], bounds[2], length=1000)                  ## bounds의 가장 작은값에서 큰값을 1000등분 한다.


> points.normal = dnorm(points.x)                                                  ## points.x를 normal 분포의 density를 구한다.
> points.t = dt(points.x, 5)                                                                 ## points.x를 t분포(자유도 5)의 density를 구한다.
> points.cauchy = dcauchy(points.x)                                              ## points.x를 cauchy분포의 density를 구한다.

> plot(0,0,type="n", xlim=bounds, ylim=c(range(c(points.normal, points.t, points.cauchy))), xlab="", ylab="Denstiy Value")

## x축의 범위는 bounds, y축의 범위는 points.normal, points.t, points.cauchy의 최대, 최소값 인 그림을 그린다.
## type="n"이라는 옵션을 통해 그림을 그리지 않는다.

> lines(points.x, points.normal, col=1, lty=1)                     ## x축은 points.x, y축은 points.normal를 이용하여 선을 그린다.
> lines(points.x, points.t,             col=2, lty=2)                    ## x축은 points.x, y축은 points.t를 이용하여 선을 그린다.
> lines(points.x, points.cauchy, col=3, lty=3)                    ## x축은 points.x, y축은 points.cauchy를 이용하여 선을 그린다.


> title("A graphical comparision od the Normal, T, and Cauchy distributions") ## 다음의 내용으로 title를 쓴다.
> legend(4,0.3, legend = c("Normal","T", "Cauchy"),lty=1:3, col=1:3 )                ## 각 lines의 설명을 그림에 추가한다.



image:R-3-1.jpeg