# [R] t-distribution

Greg Snow Greg.Snow at intermountainmail.org
Fri Aug 3 17:00:58 CEST 2007

```Look at the power.examp and run.power.examp functions in the
TeachingDemos package.  Do these do what you want?  If not you can look
at the code in them to see how to fill part of the area under the curve.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Nair,
> Murlidharan T
> Sent: Friday, August 03, 2007 8:46 AM
> To: Stephen Tucker; r-help at stat.math.ethz.ch
> Subject: Re: [R] t-distribution
>
> I am trying to shade the critical regions for normal
> distribution with different means and making overlaps of the
> plots to explain Type I and Type II errors. I tried the
> following. If I calculate the z score and as I did below, can
> I use it to pick regions from the original data? I think I am
> making mistake by calculating the z scores for d\$x, can
> someone explain the mistake I am making?
>
> left<- -1.96
> right<- 1.96
> mu1<-rnorm(100000,20,5)
> d<-(density(mu1))
> x.tmp<-d\$x
> y.tmp<-d\$y
> x<-x.tmp
> y<-y.tmp
> mu1z<-(x.tmp-mean(x.tmp))/sd(x.tmp) # is it correct?
> a<-which(mu1z <=left)
> b<-which(mu1z >=right)
> plot(x.tmp,y.tmp, type="l")
> polygon(x=c(x.tmp[a],rev(x.tmp[a])),y=c(y.tmp[a],rep(0,length(
> y.tmp[a]))
> ),col="gray90")
> polygon(x=c(x.tmp[b],rev(x.tmp[b])),y=c(y.tmp[b],rep(0,length(
> y.tmp[b]))
> ),col="gray90")
>
> -----Original Message-----
> From: Stephen Tucker [mailto:brown_emu at yahoo.com]
> Sent: Thursday, August 02, 2007 3:11 PM
> To: Nair, Murlidharan T; r-help at stat.math.ethz.ch
> Subject: RE: [R] t-distribution
>
> yes, or
>
> p <- seq(0.001,0.999,,1000)
> x <- qt(p,df=9)
> y <- dt(x,df=9)
> plot(x,y,type="l")
>
> f <- function(x,y,...) {
>   polygon(x=c(x,rev(x)),y=c(y,rep(0,length(y))),...)
> }
> with(data.frame(x,y)[x >= 2.3,],f(x,y,col="gray90"))
> with(data.frame(x,y)[x <= -2.3,],f(x,y,col="gray90"))
>
>
> --- "Nair, Murlidharan T" <mnair at iusb.edu> wrote:
>
> >
> > I tried doing it this way.
> >
> > left<--2.3
> > right<-2.3
> > p <- seq(0.001,0.999,,1000)
> > x <- qt(p,df=9)
> > y <- dt(x,df=9)
> > plot(x,y,type="l")
> > x.tmp<-x
> > y.tmp<-y
> > a<-which(x<=left)
> >
> polygon(x=c(x.tmp[a],rev(x.tmp[a])),y=c(y.tmp[a],rep(0,length(
> y.tmp[a]))
> ),col="gray90")
> > b<-which(x>=right)
> >
> polygon(x=c(x.tmp[b],rev(x.tmp[b])),y=c(y.tmp[b],rep(0,length(
> y.tmp[b]))
> ),col="gray90")
> >
> > Please let me know if I have made any mistakes.
> > Thanks ../Murli
> >
> >
> >
> > -----Original Message-----
> > From: Richard M. Heiberger [mailto:rmh at temple.edu]
> > Sent: Thu 8/2/2007 10:25 AM
> > To: Nair, Murlidharan T; Stephen Tucker; r-help at stat.math.ethz.ch
> > Subject: Re: [R] t-distribution
> >
> > I believe you are looking for the functionality I have in the
> > norm.curve function in the HH package.
> >
> > Download and install HH from CRAN and then look at
> >
> > example(norm.curve)
> >
> >
>
>
>
>
> ______________________________________________________________
> __________
> Check out tonight's top picks on Yahoo! TV.
> http://tv.yahoo.com/
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help