#######################################
######       LogLinear Analysis  	  ####
######          Paris 2019         ####
#######################################

# Libraries Needed
library(vcd)
library(MASS)

# Load and examine data from data frame - selecting only the variables you wish to examine. Note that the order of the columns will determine the order they are treated by the analysis.

d = read.table(file.choose(), header=T, sep="\t")
summary(d)

# convert dataframe to table

d = table(df)

# Run loglinear analysis (effective maximum of 4 variables)
LogLin = loglm(formula = ~ V1 + V2 +  V3 , data = d)

# Plot the results in a mosaic plot
mosaic(LogLin, legend_args = list(fontsize = 8 ), labeling_args = list(
gp_labels = gpar(fontsize = 8, fontface = 1,  fontfamily = "Times New Roman"),
gp_varnames = gpar(fontsize = 10, fontface = 2, fontfamily = "Times New Roman")))