suppressPackageStartupMessages({
require(readxl)
require(ggplot2)
require(car)
require(glmmTMB)
require(DHARMa)
require(lme4)
require(MASS)
require(pwr)
library(rvg)
library(Hmisc)
library (ggplot2)
library (lme4)
library (nlme)
library (multcomp)
library (readxl)
library (grid)
library (gridExtra)
library (dplyr)
library (scales)
library (lattice)
library (MASS)
library(rvg)
library(Hmisc)
library(simr)
library(betareg)
library(lmtest)
})
dualfeeder <- read_excel("C:/Users/LocalAdmin/Documents/ThomasWagnerPhD/PhD/MyPublication/PhD/DeltaFeederPaper/Pest Management/New/Power/DF_D2_Sucrose_Quinine_ControlsSide.xlsx")
First we will only include experiments in which ants did quinine vs sucurose. Then we will throw out all the ants which hit the control solution first. Then we will make an indicator variable telling us if quinine is on the right (1) or the left (0).
dualfeeder$time_initial_choice_s = ifelse(dualfeeder$Initial_Decision == "L", dualfeeder$Drinking_Time_Left_s, dualfeeder$Drinking_Time_Right_s)
dualfeeder$prop_time_initial_choice = dualfeeder$time_initial_choice_s / (dualfeeder$Drinking_Time_Left_s + dualfeeder$Drinking_Time_Right_s)
dualfeeder$prop_time_initial_choice = ifelse(dualfeeder$prop_time_initial_choice == 1, NA, dualfeeder$prop_time_initial_choice)
dualfeeder$solution_initial_choice = ifelse(dualfeeder$Initial_Decision == "L", dualfeeder$Solution_Left, dualfeeder$Solution_Right)
dualfeeder$solution_initial_choice = ifelse((dualfeeder$Solution_Left == "1M Sucrose") & (dualfeeder$Solution_Right == "1M Sucrose"), "1M_L", dualfeeder$solution_initial_choice)
dualfeeder$solution_initial_choice = ifelse((dualfeeder$Solution_Left == "1M Sucrose") & (dualfeeder$Solution_Right == "1M Sucrose") & (dualfeeder$Initial_Decision == "R"), "1M_R", dualfeeder$solution_initial_choice)
table(dualfeeder$Initial_Decision)
##
## L R
## 86 145
onlyvsquinine <- subset(dualfeeder, Experiment == "1M_Quinine")
dataforlateralisation <- subset (onlyvsquinine, solution_initial_choice != "0.5M Sucrose")
dataforlateralisation <- subset (onlyvsquinine, solution_initial_choice != "1M Sucrose")
dataforlateralisation <- dataforlateralisation %>%
mutate(Quinine_on_right = as.integer(Solution_Left == "1M Sucrose"))
ggplot(dataforlateralisation, aes(x = as.factor(Quininepair), y = prop_time_initial_choice, fill = factor(Quinine_on_right))) +
geom_bar(stat = "summary", fun = "mean", position = position_dodge()) +
labs(x = "Quinine Pair", y = "Mean Prop Time Initial Choice", fill = "Quinine on Right") +
scale_fill_discrete(labels = c("No", "Yes")) +
theme_minimal()
## Warning: Removed 17 rows containing non-finite values (stat_summary).
No obvious difference.
We are using a Beta regression to test whether quinine level and (importantly) quinine side predicts our outcome. The ReducedModel represents the model without our tested potential predictor variable, “Quinine_on_right”. To evaluate its significance, we compare this model to the complete model, lateralModel, which includes “Quinine_on_right”. This comparison allows us to test whether the inclusion of “Quinine_on_right” leads to a significant improvement in model fit, potentially indicating a lateralisation effect.
lateralModel <- betareg(prop_time_initial_choice ~ as.factor(Quininepair) + Quinine_on_right,
data = dataforlateralisation)
summary(lateralModel)
##
## Call:
## betareg(formula = prop_time_initial_choice ~ as.factor(Quininepair) +
## Quinine_on_right, data = dataforlateralisation)
##
## Standardized weighted residuals 2:
## Min 1Q Median 3Q Max
## -2.3465 -0.7258 0.1032 0.6408 2.5883
##
## Coefficients (mean model with logit link):
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.59224 0.24045 2.463 0.0138 *
## as.factor(Quininepair)0.313 -0.09378 0.25980 -0.361 0.7181
## as.factor(Quininepair)0.625 -0.25135 0.25347 -0.992 0.3214
## Quinine_on_right 0.14581 0.20979 0.695 0.4870
##
## Phi coefficients (precision model with identity link):
## Estimate Std. Error z value Pr(>|z|)
## (phi) 2.666 0.332 8.031 9.7e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Type of estimator: ML (maximum likelihood)
## Log-likelihood: 13.42 on 5 Df
## Pseudo R-squared: 0.01768
## Number of iterations: 20 (BFGS) + 1 (Fisher scoring)
reducedModel <- betareg(prop_time_initial_choice ~ as.factor(Quininepair),
data = dataforlateralisation)
lrtest(lateralModel, reducedModel)
## Likelihood ratio test
##
## Model 1: prop_time_initial_choice ~ as.factor(Quininepair) + Quinine_on_right
## Model 2: prop_time_initial_choice ~ as.factor(Quininepair)
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 5 13.416
## 2 4 13.176 -1 0.4799 0.4885
There is no evidence to suggest that lateralisation occurred, as the results were not statistically significant.