Hi Ali:
 
Try this for the Chi-Square test statistic.
 
good luck
abou
 
 
###############################################################
par(mfrow = c(1,2))

shade.dchisq <- function(df,ncp,a,b, Col="red"){

    #add to plot of normal density, shading area between a and b

    n <- 100
    x <- seq(a,b,length=n)
    y <- dchisq(x,df,ncp)
    X = c(x[1],x,x[n])
    Y =c(0,y,0)
    polygon(X,Y,col=Col)
}

shade.dchisq1 <- function(df,ncp,a,b, density=30){

    #add to plot of chi-square density, shading area between a and b

    n <- 100
    x <- seq(a,b,length=n)
    y <- dchisq(x,df,ncp)
    X = c(x[1],x,x[n])
    Y =c(0,y,0)
    polygon(X,Y,density=density)
}

#### example:

x <- seq(0,20,.01)
y <- dchisq(x,3,0)    ### df=5, ncp=0

x1<-seq(0,20,0.01)
y1<-dchisq(x,3,2)      ### df=5, ncp=2   

plot(x,y,type="l", ylab="density", lwd=3,col="red")  ### xlim=c(-7,10), 

#### title(main="Distributions of T under H0 and Ha")

title(main="                Distributions of T")

lines(x1,y1,lwd=3, col="blue")


shade.dchisq1(3,2,9,20,30)

shade.dchisq(3,0,9,20)


abline(h=0,lwd=3)




#### add legend

chicurve<-c("nc=0","nc=2")

legend(list(x=9,y=0.23), legend = chicurve, col=c("red","blue"), cex=1.0, 
lwd=2, lty=1, merge=TRUE)#, trace=TRUE)




####################################    Chi-Square test     
###########################

shade.dchisq <- function(df,ncp,a,b, Col="red"){

    #add to plot of normal density, shading area between a and b

    n <- 100
    x <- seq(a,b,length=n)
    y <- dchisq(x,df,ncp)
    X = c(x[1],x,x[n])
    Y =c(0,y,0)
    polygon(X,Y,col=Col)
}

shade.dchisq1 <- function(df,ncp,a,b, density=30){

    #add to plot of chi-square density, shading area between a and b

    n <- 100
    x <- seq(a,b,length=n)
    y <- dchisq(x,df,ncp)
    X = c(x[1],x,x[n])
    Y =c(0,y,0)
    polygon(X,Y,density=density)
}

#### example:

x <- seq(0,20,.01)
y <- dchisq(x,3,0)    ### df=3, ncp=0

x1<-seq(0,20,0.01)
y1<-dchisq(x,3,5)      ### df=3, ncp=5   

plot(x,y,type="l", ylab="density", lwd=3,col="red")  ### xlim=c(-7,10), 

##### title(main="Distributions of T under H0 and Ha")

title(main="under H0 and Ha                               ")

lines(x1,y1,lwd=3, col="blue")


shade.dchisq1(3,5,9,20,30)
shade.dchisq(3,0,9,20)

abline(h=0,lwd=3)


#### add legend

chicurve<-c("nc=0","nc=5")

legend(list(x=9,y=0.23), legend = chicurve, col=c("red","blue"), cex=1.0, 
lwd=2, lty=1, merge=TRUE)#, trace=TRUE)

################################################################







==========================
AbouEl-Makarim Aboueissa, Ph.D.
Associate Professor of Statistics
Graduate Program Coordinator
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300
USA


Tel: (207) 228-8389
Fax: (207) 780-5607
Email: [email protected]
          [email protected]

Office: 301C Payson Smith

>>> Ali Zanaty <[email protected]> 4/15/2012 11:14 AM >>>
Dear All: 

  



I need a quick help in R. How I can plot plot the distribution of the T test 
statistic under Ho and Ha with shading areas. Plot overlapping two T 
distributions and shading overlapping areas under both curves. You choose any 
values just
for example. I could not upload any graph for example.

  



Once I know how to create this one, I think I will be able to create the one 
for normal case.



Thank you very much and sorry for bothering.



Ali


[[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching

        [[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching

Reply via email to