Load in the data.

setwd('/Users/lachlanphillips/Development/other_people_help/BIOL703/lincoln')
df <- read.csv('mockdata.csv')[,2:3]

Drop cases with a ‘none’ reponse.

# drop none
df <- df[!df$initial_spider_response == 'none',]
# drop none level as factor
df$initial_spider_response <- droplevels(df$initial_spider_response)

Plot the data. We make a table to tabulate the results and when making the plot we transpose (swap rows with columns) the table using t(df.tab) so the treatment is the x-axis.

df.tab <- table(df)
par(mar = c(5,4,4,8))
barplot(t(df.tab), ylab='Response frequency', xlab='', main="",
        xlim=c(0,1), width=.3,
        legend.text=TRUE, col=c('firebrick','grey'), border = NA,
        args.legend=list(x = "topright", xpd=TRUE))

Build logistic regression model.

fit <- glm(initial_spider_response ~ burrow_vibration_treatment, df, family=binomial(link="logit"))

Check results.

summary(fit)
## 
## Call:
## glm(formula = initial_spider_response ~ burrow_vibration_treatment, 
##     family = binomial(link = "logit"), data = df)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.7941  -0.7876   0.6681   0.6681   1.6259  
## 
## Coefficients:
##                                 Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                       1.3863     0.6455   2.148  0.03174 * 
## burrow_vibration_treatmentbelow  -2.3979     0.8704  -2.755  0.00587 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 41.455  on 29  degrees of freedom
## Residual deviance: 32.410  on 28  degrees of freedom
## AIC: 36.41
## 
## Number of Fisher Scoring iterations: 4