# This code is stored in the file fden.spl #================================================# # f.density.plot() # --------------------------------------------- # Input : degrees of freedom; it can be a vector. # (e.g.) f.density.plot(c(1,10,10,50)) # creates a plot with density curves # for (1,10) df and (10,50) df # Output: density plots of the central F # distribution. # ################################################# f.density.plot <- function(n) { # draw x,y axis and title x <- seq(.001,4,,50) plot(c(0,4), c(0,1.4), type="n", xlab="x", ylab="f(x;n)", main="Densities for Central F Distributions") # the length of df should be even. legend.txt <- NULL d.f <- matrix(n,ncol=2,byrow=T); r <- dim(d.f)[1] for(i in 1:r) { lty.num <- 3*i-2 # specify the line types. f.x <- df(x,d.f[i,1],d.f[i,2]) # calculate density. lines(x, f.x, type="l",lty=lty.num) # draw a line. legend.txt <- c(legend.txt, paste("(",d.f[i,1],",",d.f[i,2],")",sep="")) } # The following lines are for inserting # legends on plots using a motif # graphics window. legend( x = rep(1.9,r) , y = rep(1.1,r) , cex=1.0, legend = paste(legend.txt,"df") , lty = seq(1,by=3,length=r) , bty = "n" ) } # This function can be executed with the following # commands. # # par(fin=c(6,7),cex=1.0,mex=1.3,lwd=4) # source("fden.spl") # f.density.plot(c(1,10,10,50,10,10,10,4))