######################
#Plotting the f distribution
######################
#load some packages
library(ggplot2)
library(dplyr)
library(tidyr)
#R has the f distribution built into it. It is called f
#R also has functions built into it to work with distributions. One of them is called d. It gives you the probability density function for your chosen distribution.
#The way you use these is that you combine the two names into one function. So the density functon for the f distribution is df().
#The density function for the normal distribution is dnorm()
#The first thing we need to do is choose our list of F's. To keep the graph manageable, I will choose fs between 0 and 5
F.values <- seq(.001,5,len=999)
#Now we need to choose the dfs we want to explore
#df1 will be 1 for these, because that is the most common in our experiments
df1 = df(F.values, 1, 1)
df2 = df(F.values, 1, 2)
df5 = df(F.values, 1, 5)
df10 = df(F.values, 1, 10)
df100 = df(F.values, 1, 100)
#create a data.frame
F.distribution = data.frame(F.values, df1, df2, df5, df10, df100)
#convert it to long format
F.distribution.long = gather(F.distribution, key = DF, value=density, df1:df100)
#
p1 = ggplot(F.distribution.long, aes(x=F.values, y=density, group = DF, color=DF)) + geom_line() + theme(axis.title.x = element_text(vjust=-0.5))+ scale_color_brewer(type="qual", palette=6) +theme(axis.title.y = element_text(vjust=1))+guides(fill = FALSE) + theme(legend.position="bottom") + scale_y_continuous(limits=c(0,2.25))
########
#Now let's do it again, this time with df1 being 100
########
#The first thing we need to do is choose our list of F's. To keep the graph manageable, I will choose fs between 0 and 5
F.values <- seq(.001,5,len=999)
#Now we need to choose the dfs we want to explore
#df1 will be 1 for these, because that is the most common in our experiments
df1 = df(F.values, 100, 1)
df2 = df(F.values, 100, 2)
df5 = df(F.values, 100, 5)
df10 = df(F.values, 100, 10)
df100 = df(F.values, 100, 100)
#create a data.frame
F.distribution = data.frame(F.values, df1, df2, df5, df10, df100)
#convert it to long format
F.distribution.long = gather(F.distribution, key = DF, value=density, df1:df100)
#
p = ggplot(F.distribution.long, aes(x=F.values, y=density, group = DF, color=DF)) + geom_line() + theme(axis.title.x = element_text(vjust=-0.5))+ scale_color_brewer(type="qual", palette=6) +theme(axis.title.y = element_text(vjust=1))+guides(fill = FALSE) + theme(legend.position="bottom") + scale_y_continuous(limits=c(0,2.25))