This document is my attempt to determine whether my quantification of nociception predicted avoidance learning via time in each zone (dark, light, middle)

data<-Behavioral.Trials.All.Data

Variable Transformations

#LIGHT
#Make new column with no 0 values
min_val <- min(data$light)
data$light_shift <- data$light + abs(min_val) + 1
#Transform
lambda <- 0.1262881
data$light_trans <- data$light_shift ^ lambda

#MIDDLE
#make new column with no 0 values
min_val <- min(data$middle)
data$mid_shift <- data$middle + abs(min_val) + 1
#Transform
lambda <- 0.06642153
data$mid_trans <- data$mid_shift ^ lambda

#DARK
#dark is normal enough. Transformation below increases skewness.

#make new column with no 0 values
min_val <- min(data$dark)
data$dark_shift <- data$dark + abs(min_val) + 1
#Transform
lambda <- 0.8567983 
data$dark_trans <- data$dark_shift ^ lambda
#Separate trials
T1<- data[data$trial=="1",]
T2<- data[data$trial=="2",]
T3<- data[data$trial=="3",]
data23<- rbind(T2,T3)

#separate experiments
exp1<-(data[data$exp=="1",])
exp2<-(data[data$exp=="2",])

#separate treatment groups
hot<-(data[data$hot=="y",])
control<-(data[hot$exp=="n",])

Plots

ggplot(data, aes(x = tailflip, y = light_trans)) +
  geom_jitter(width = 0.1, height = 0, alpha = 0.6) +
  geom_smooth(method = "lm", se = TRUE, color = "black") +
  theme_minimal() +
  labs(title = "Tailflips vs. Transformed Time in Light",
       x = "Tailflips per Trial", y = "Transformed Time in Light")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(data, aes(x = tailflip, y = mid_trans)) +
  geom_jitter(width = 0.1, height = 0, alpha = 0.6) +
  geom_smooth(method = "lm", se = TRUE, color = "black") +
  theme_minimal() +
  labs(title = "Tailflips vs. Transformed Time in Middle",
       x = "Tailflips per Trial", y = "Transformed Time in Middle")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(data, aes(x = tailflip, y = dark)) +
  geom_jitter(width = 0.1, height = 0, alpha = 0.6) +
  geom_smooth(method = "lm", se = TRUE, color = "black") +
  theme_minimal() +
  labs(title = "Tailflips vs. Transformed Time in Dark",
       x = "Tailflips per Trial", y = "Time in Dark")
## `geom_smooth()` using formula = 'y ~ x'

#AS YOU CAN SEE BELOW, LIGHT HAD WEAK POSITIVE TREND ASSOCIATED WITH TAILFLIPS AND DARK HAD WEAK NEGATIVE TREND ASSOCIATED WITH TAILFLIPS

Modelling

#IN ALL MODELS, INTERACTION TERM TAILFLIP * HOT WAS NOT SIGNIFICANT, DID NOT IMPROVE THE MODEL

Is tailflip predictive of Light?

# Fit linear mixed-effects model
model_tailflip_light <- lmer(light_trans ~ tailflip + (1 | subject) + (1 | trial), data = data)
#interaction with hot here is non significant and does not improve the model. 
# View model summary
summary(model_tailflip_light)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: light_trans ~ tailflip + (1 | subject) + (1 | trial)
##    Data: data
## 
## REML criterion at convergence: 121.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.2388 -0.7377  0.1322  0.5938  2.5073 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  subject  (Intercept) 0.0535258 0.23136 
##  trial    (Intercept) 0.0007442 0.02728 
##  Residual             0.1046467 0.32349 
## Number of obs: 138, groups:  subject, 23; trial, 3
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   1.50908    0.06197  15.49571  24.353    9e-14 ***
## tailflip      0.01638    0.01208 123.96213   1.356    0.178    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##          (Intr)
## tailflip -0.363

#weak positive trend

#Checking Residuals

plot(model_tailflip_light)                  # Residuals vs. fitted

qqnorm(resid(model_tailflip_light))        # Q-Q plot
qqline(resid(model_tailflip_light))

#residuals look good

#Testing whether ANY tail flipping predicts light:

data$tailflip_binary <- ifelse(data$tailflip > 0, 1, 0)

model_tailflip_binary <- lmer(light_trans ~ tailflip_binary + (1 | subject) + (1 | trial), data = data)

summary(model_tailflip_binary)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: light_trans ~ tailflip_binary + (1 | subject) + (1 | trial)
##    Data: data
## 
## REML criterion at convergence: 117.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.3604 -0.7369  0.1426  0.6083  2.5034 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subject  (Intercept) 0.050695 0.22516 
##  trial    (Intercept) 0.001103 0.03321 
##  Residual             0.104377 0.32307 
## Number of obs: 138, groups:  subject, 23; trial, 3
## 
## Fixed effects:
##                  Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)       1.48329    0.06660  18.63758  22.271  6.9e-15 ***
## tailflip_binary   0.10091    0.05964 124.34091   1.692   0.0932 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## talflp_bnry -0.500

#weak positive estimate.

#Trials with tailflips spent 0.09 transformed units more time in the light. Not significant

Is tailflip predictive of Dark?

# Fit linear mixed-effects model
model_tailflip_dark <- lmer(dark ~ tailflip + (1 | subject), data = data)
#interaction here is not significant and greatly increases uncertainty
#trial had 0 variance in this model, took it out
# View model summary
summary(model_tailflip_dark)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dark ~ tailflip + (1 | subject)
##    Data: data
## 
## REML criterion at convergence: 1822.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5758 -0.4027  0.1893  0.6492  1.8485 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subject  (Intercept)  7215     84.94  
##  Residual             30778    175.44  
## Number of obs: 138, groups:  subject, 23
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  413.006     26.079  33.270  15.837   <2e-16 ***
## tailflip      -7.323      6.429 131.057  -1.139    0.257    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##          (Intr)
## tailflip -0.459

#no - weak negative trend

#Each additional tailflip weakly predicts ~7 units less time in the dark

#Checking Residuals

plot(model_tailflip_dark)                  # Residuals vs. fitted

qqnorm(resid(model_tailflip_dark))        # Q-Q plot
qqline(resid(model_tailflip_dark))

#residuals look pretty good

# Testing whether ANY tail flipping predicts dark:

model_tailflip_binaryd <- lmer(dark ~ tailflip_binary + (1 | subject) + (1 | trial), data = data)
## boundary (singular) fit: see help('isSingular')
summary(model_tailflip_binaryd)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dark ~ tailflip_binary + (1 | subject) + (1 | trial)
##    Data: data
## 
## REML criterion at convergence: 1820.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5585 -0.4248  0.1975  0.6773  1.6283 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. 
##  subject  (Intercept) 7.097e+03 8.424e+01
##  trial    (Intercept) 3.502e-11 5.918e-06
##  Residual             3.111e+04 1.764e+02
## Number of obs: 138, groups:  subject, 23; trial, 3
## 
## Fixed effects:
##                 Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)       391.87      29.19  48.13   13.43   <2e-16 ***
## tailflip_binary    13.43      31.96 130.57    0.42    0.675    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## talflp_bnry -0.611
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

#not at all

Is tailflip predictive of Middle?

# Fit linear mixed-effects model
model_tailflip_mid <- lmer(mid_trans ~ tailflip + (1 | subject) + (1 | trial), data = data)

# View model summary
summary(model_tailflip_mid)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: mid_trans ~ tailflip + (1 | subject) + (1 | trial)
##    Data: data
## 
## REML criterion at convergence: -102.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.89162 -0.60076  0.03973  0.62856  1.97621 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subject  (Intercept) 0.002297 0.04793 
##  trial    (Intercept) 0.001005 0.03171 
##  Residual             0.023082 0.15193 
## Number of obs: 138, groups:  subject, 23; trial, 3
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept) 1.249e+00  2.656e-02 3.830e+00  47.045 1.96e-06 ***
## tailflip    6.432e-04  5.451e-03 1.331e+02   0.118    0.906    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##          (Intr)
## tailflip -0.382

#not at all

#Checking Residuals

plot(model_tailflip_mid)                  # Residuals vs. fitted

qqnorm(resid(model_tailflip_mid))        # Q-Q plot
qqline(resid(model_tailflip_mid))

#residuals look good

# Testing whether ANY tail flipping predicts middle:

model_tailflip_binarym <- lmer(mid_trans ~ tailflip_binary + (1 | subject)+ (1 | trial), data = data)

summary(model_tailflip_binarym)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: mid_trans ~ tailflip_binary + (1 | subject) + (1 | trial)
##    Data: data
## 
## REML criterion at convergence: -106.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.00295 -0.62452  0.05746  0.62950  1.99137 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subject  (Intercept) 0.002281 0.04776 
##  trial    (Intercept) 0.001115 0.03339 
##  Residual             0.022876 0.15125 
## Number of obs: 138, groups:  subject, 23; trial, 3
## 
## Fixed effects:
##                  Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)       1.26618    0.02936   4.98434  43.120 1.32e-07 ***
## tailflip_binary  -0.02794    0.02693 133.01195  -1.038    0.301    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## talflp_bnry -0.512

#no. negative estimate