GaryBAYLOR / R-code

A collection of algorithms written by myself for solving statistical problems
0 stars 0 forks source link

F distribution with different degree of freedom #5

Open GaryBAYLOR opened 9 years ago

GaryBAYLOR commented 9 years ago

We want to compare F distributions with different degree of freedoms. The following is the plot. image

image

image

The code is as following.

x <- seq(0, 3, by = 0.01) 

##  df1 = 1, df2 = 1, 2, 3, 5, 10, 20
y1.1 <- df(x, 1, 1)
y1.2 <- df(x, 1, 2)
y1.3 <- df(x, 1, 3)
y1.5 <- df(x, 1, 5)
y1.10 <- df(x, 1, 10)
y1.20 <- df(x, 1, 20)
    ##  plot
plot(x, y1.1, type = "l", ylim = c(0, 2.5), col = "black", xlab = "X", ylab = "density of F", main = "density of F for different df")
lines(x, y1.2, type = "l", col = "red")
lines(x, y1.3, type = "l", col = "green")
lines(x, y1.5, type = "l", col = "black", lty = 2)
lines(x, y1.10, type = "l", col = "red", lty = 2)
lines(x, y1.20, type = "l", col = "green", lty = 2)
legend(2.2, 2.5, 
    legend = c("d1 = 1, d2 = 1", "d1 = 1, d2 = 2", "d1 = 1, d2 = 3", "d1 = 1, d2 = 5", "d1 = 1, d2 = 10", "d1 = 1, d2 = 20"),
    col = c("black", "red", "green", "black", "red", "green"), lty = c(1,1,1,2,2,2) 
    )

    ##  df1 = 5, df2 = 1, 2, 3, 5, 10, 20
y1.1 <- df(x, 5, 1)
y1.2 <- df(x, 5, 2)
y1.3 <- df(x, 5, 3)
y1.5 <- df(x, 5, 5)
y1.10 <- df(x, 5, 10)
y1.20 <- df(x, 5, 20)
    ##  plot
plot(x, y1.1, type = "l", ylim = c(0, 2.5), col = "black", xlab = "X", ylab = "density of F", main = "density of F for different df")
lines(x, y1.2, type = "l", col = "red")
lines(x, y1.3, type = "l", col = "green")
lines(x, y1.5, type = "l", col = "black", lty = 2)
lines(x, y1.10, type = "l", col = "red", lty = 2)
lines(x, y1.20, type = "l", col = "green", lty = 2)
legend(2.2, 2.5, 
    legend = c("d1 = 5, d2 = 1", "d1 = 5, d2 = 2", "d1 = 5, d2 = 3", "d1 = 5, d2 = 5", "d1 = 5, d2 = 10", "d1 = 5, d2 = 20"),
    col = c("black", "red", "green", "black", "red", "green"), lty = c(1,1,1,2,2,2) 
    )

    ##  df1 = 1, 2, 3, 5, 10, 20, df2 = 5
y1.1 <- df(x, 1, 5)
y1.2 <- df(x, 2, 5)
y1.3 <- df(x, 3, 5)
y1.5 <- df(x, 5, 5)
y1.10 <- df(x, 10, 5)
y1.20 <- df(x, 20, 5)
    ##  plot
plot(x, y1.1, type = "l", ylim = c(0, 2.5), col = "black", xlab = "X", ylab = "density of F", main = "density of F for different df")
lines(x, y1.2, type = "l", col = "red")
lines(x, y1.3, type = "l", col = "green")
lines(x, y1.5, type = "l", col = "black", lty = 2)
lines(x, y1.10, type = "l", col = "red", lty = 2)
lines(x, y1.20, type = "l", col = "green", lty = 2)
legend(2.2, 2.5, 
    legend = c("d1 = 1, d2 = 5", "d1 = 2, d2 = 5", "d1 = 3, d2 = 5", "d1 = 5, d2 = 5", "d1 = 10, d2 = 5", "d1 = 20, d2 = 5"),
    col = c("black", "red", "green", "black", "red", "green"), lty = c(1,1,1,2,2,2) 
    )