EDIT: SOLUTION FOUND, SEE BELOW QUESTION
I'm an undergrad writing a very simple lab report in which I'm analysing some data on observed numbers of birds at two different study sites. The exact data frame I'm using was imported off an Excel spreadsheet but I'll replicate the data frame here.
Location <- c(rep("Leighton Moss",6),rep("Eaves Wood",6)
Period<-c(rep(c(rep("Midday",3),rep("Afternoon",3)),2))
Activity<-c(rep(c("Resting","Foraging","Travelling"),4))
Count<-c(88,68,54,30,41,33,13,28,13,55,47,46)
df<-data.frame(Location,Period,Activity,Count)
I want to know if there's an equivalent of Chi-squared test of association for three categorical variables (in this case Location, Period and Activity) as opposed to two.
I ideally want to avoid just doing separate three separate Chi-squared tests for Location vs Activity, Period vs Activity and Location vs Period, but I've found the solution to code for that in case I do need to do that.
I think I can build a three-way contingency table like this to help:
Beyond that I'm not sure what analysis to do as I think multilinear regression involves a continuous variable? Any code/function that I can use to do this would be great.
Any help y'all can offer is always much appreciated.
Solution
The answer posted below by a fellow commenter had Activity as a covariate which wasn't what I was after; however, I adapted that answer to suit my needs. In the end, I went for a two-pronged analysis.
Firstly, a multinomial logistic regression analysis using the multinom
function of the AER
package, with Activity as the outcome variable and Period and Location as predictor variables. To do this I listed each observation individually rather than using count data, and the following line of code.
multi_mo<-multinom(Activity ~ Location + Period + Location*Period, data=[data frame name], model=TRUE)
summary(multi_mo)
Secondly, I separated the count data by Activity category, and conducted Poisson regressions on each individual Activity category with Period and Location as covariates. This was just done using the glm
function, as shown below.
Resting_Model <- glm(Resting_Count ~ Location + Period + Location:Period,
family="poisson",
offset=log(Total_Observations),
data=[data frame name])
summary(Resting_Model)
Hopefully this helps someone with the same question!