# This code is stored in: chiden.ssc #================================================# # chisq.density.plot() # # ------------------------ # # Input : degrees of freedom; it can be a vector.# # (e.g.) chisq.density.plot(c(1,2,5,7))# # creates curves for df = 1,3,5,and 7 # # Output: density plot of chisquare distribution.# # # ################################################## chisq.density.plot <- function(df) { x <- seq(.001,10,,50) # draw x,y axis and title plot(c(0,10), c(0,.5), type="n", xlab="x", ylab="f(x;df)", main="Central Chi-Square Densities") for(i in 1:length(df)) { lty.num <- 3*i-2 # specify the line types. f.x <- dchisq(x,df[i]) # calculate density. lines(x, f.x, type="l",lty=lty.num) # draw spline. } # The following lines are for legends; legend( x = rep(5,length(df)) , y = rep(.45,length(df)) , legend = paste(as.character(df),"df") , lty = seq(1,by=3,length=length(df)) , bty = "n") } # This function can be executed with # the following commands. The source( ) # function enters the entire file into # the command window and executes all # of the commands in the file. # # source("chiden.ssc") # par(fin=c(6,8),cex=1.2,mex=1.5,lwd=4) # chisq.density.plot(c(1,3,5,7))