Statistical Modeling Experimental Analysis of Cognitive Effects

Evaluate nicotine’s cognitive effects by employing statistical models in R. Retrieved data collection with 60 participants and developed a randomized complete block design (RCBD). Cleaned data and created tailored data visualizations comparing memory performance pre and post nicotine use. Utilized R for statistical modeling, including ANOVA, paired t-tests, and power calculations.
Author

Nicole Lee

Published

June 9, 2024

Download the Report

df <- read.csv("C:/Users/nicol/OneDrive/Desktop/stats140/personal-website/projects/stats101b_project_data.csv")
head(df)
              Name  Village House Age    Sex Smoking.Status NoCig   Cig Over50
1    ANAMICA PRICE   Helvig    94  18 female      nonsmoker  50.2  50.2     -1
2    AGDA SORENSEN   Helvig    41  21 female      nonsmoker  49.6  42.5     -1
3  KAYLEIGH KIMURA Bjurholm   189  21 female      nonsmoker  50.9  61.8     -1
4 JACKSON CONNOLLY Bjurholm   156  23   male   light smoker  39.5  37.7     -1
5 ABIGAIL WATANABE    Vardo     7  23 female    lightsmoker  61.6  51.0     -1
6       JACOB HALL Bjurholm   419  24   male      nonsmoker 114.0 120.0     -1

Reorganizing data

library(tidyr)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
df_long <- df %>%
  pivot_longer(cols = c(NoCig, Cig), 
               names_to = "cigarette", 
               values_to = "memory") %>%
  mutate(cigarette = ifelse(cigarette == "NoCig", -1, 1))

df2 <- df_long %>% select(c("Over50", "cigarette", "memory"))
head(df2)
# A tibble: 6 × 3
  Over50 cigarette memory
   <int>     <dbl>  <dbl>
1     -1        -1   50.2
2     -1         1   50.2
3     -1        -1   49.6
4     -1         1   42.5
5     -1        -1   50.9
6     -1         1   61.8

ANOVA test for RCBD with cigarette treatment and age block

m1 <- aov(memory~cigarette+Over50, data=df2)
summary(m1)
             Df Sum Sq Mean Sq F value Pr(>F)
cigarette     1     73   73.48   0.419  0.519
Over50        1      8    8.03   0.046  0.831
Residuals   117  20529  175.47               
# Test with no block
summary(aov(memory~cigarette,data=df2))
             Df Sum Sq Mean Sq F value Pr(>F)
cigarette     1     73   73.48   0.422  0.517
Residuals   118  20538  174.05               

Power Calculations

library(pwr)
Warning: package 'pwr' was built under R version 4.4.3
d <- 1.565
f <- d/sqrt(73.48)
pwr.anova.test(k=2, n=60, f=f ,sig.level=0.05)

     Balanced one-way analysis of variance power calculation 

              k = 2
              n = 60
              f = 0.1825701
      sig.level = 0.05
          power = 0.5094948

NOTE: n is number in each group

Paired t-test with cigarette treatment, no blocks

var.test(df$NoCig, df$Cig)

    F test to compare two variances

data:  df$NoCig and df$Cig
F = 0.78012, num df = 59, denom df = 59, p-value = 0.3429
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.4659871 1.3060303
sample estimates:
ratio of variances 
         0.7801239 
t.test(df$NoCig,df$Cig, paired=T, var.equal=T)

    Paired t-test

data:  df$NoCig and df$Cig
t = 1.9963, df = 59, p-value = 0.05053
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
 -0.003698997  3.133698997
sample estimates:
mean difference 
          1.565 

Checking Model Adequacy

res1 <- m1$residuals
qqnorm(res1); qqline(res1)

plot(m1, 1)