R Markdown

FF <- read_csv("FuncFixData.csv")
## Rows: 56 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Group_SW, time, Session_1_2
## dbl (2): Participants, insight
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(FF)
## # A tibble: 6 × 5
##   Participants Group_SW time     insight Session_1_2
##          <dbl> <chr>    <chr>      <dbl> <chr>      
## 1            1 sleep    Session1       3 evening    
## 2            2 sleep    Session1       1 evening    
## 3            3 sleep    Session1       3 evening    
## 4            4 sleep    Session1       3 evening    
## 5            5 sleep    Session1       2 evening    
## 6            6 sleep    Session1       1 evening
FF$Participants = as.factor(FF$Participants)
FF$Group_SW = as.factor(FF$Group_SW)
FF$time = as.factor(FF$time)
FF$Session_1_2 = as.factor(FF$Session_1_2)
str(FF)
## spc_tbl_ [56 × 5] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ Participants: Factor w/ 28 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ Group_SW    : Factor w/ 2 levels "sleep","wake": 1 1 1 1 1 1 1 1 1 1 ...
##  $ time        : Factor w/ 2 levels "Session1","Session2": 1 1 1 1 1 1 1 1 1 1 ...
##  $ insight     : num [1:56] 3 1 3 3 2 1 3 2 3 2 ...
##  $ Session_1_2 : Factor w/ 2 levels "evening","morning": 1 1 1 1 1 1 1 1 1 1 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   Participants = col_double(),
##   ..   Group_SW = col_character(),
##   ..   time = col_character(),
##   ..   insight = col_double(),
##   ..   Session_1_2 = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
FF %>%
  group_by(Session_1_2, Group_SW) %>%
  get_summary_stats(insight, type = "mean_sd")
## # A tibble: 4 × 6
##   Group_SW Session_1_2 variable     n  mean    sd
##   <fct>    <fct>       <fct>    <dbl> <dbl> <dbl>
## 1 sleep    evening     insight     14  1.93 0.997
## 2 wake     evening     insight     14  1.86 0.864
## 3 sleep    morning     insight     14  2.71 0.994
## 4 wake     morning     insight     14  2.64 0.929
##outliers?
library(rstatix)
FF %>%
  group_by(Session_1_2, Group_SW) %>%
  identify_outliers(insight)
## [1] Group_SW     Session_1_2  Participants time         insight     
## [6] is.outlier   is.extreme  
## <0 rows> (or 0-length row.names)

Two-way mixed ANOVA test

res.aov <- anova_test(
  data = FF, dv = insight, wid = Participants,
  between = Group_SW, within = time, effect.size = "pes")
get_anova_table(res.aov)
## ANOVA Table (type II tests)
## 
##          Effect DFn DFd     F     p p<.05   pes
## 1      Group_SW   1  26 0.080 0.780       0.003
## 2          time   1  26 0.000 1.000       0.000
## 3 Group_SW:time   1  26 9.621 0.005     * 0.270
## post-hoc test
#Simple main effect of group variable. 
#we’ll investigate the effect of the between-subject factor group on insight score at every time point.

# Effect of group at each time point
one.way <- FF %>%
  group_by(time) %>%
  anova_test(dv = insight, wid = Participants, between = Group_SW, effect.size = "pes") %>%
  get_anova_table() %>%
  adjust_pvalue(method = "bonferroni")
one.way
## # A tibble: 2 × 9
##   time     Effect     DFn   DFd     F     p `p<.05`   pes p.adj
##   <fct>    <chr>    <dbl> <dbl> <dbl> <dbl> <chr>   <dbl> <dbl>
## 1 Session1 Group_SW     1    26  3.85 0.061 ""      0.129 0.122
## 2 Session2 Group_SW     1    26  5.92 0.022 "*"     0.186 0.044
# Pairwise comparisons between group levels
pwc <- FF %>%
  group_by(time) %>%
  pairwise_t_test(insight ~ Group_SW, p.adjust.method = "bonferroni")
pwc
## # A tibble: 2 × 10
##   time     .y.     group1 group2    n1    n2      p p.signif  p.adj p.adj.signif
## * <fct>    <chr>   <chr>  <chr>  <int> <int>  <dbl> <chr>     <dbl> <chr>       
## 1 Session1 insight sleep  wake      14    14 0.0607 ns       0.0607 ns          
## 2 Session2 insight sleep  wake      14    14 0.0221 *        0.0221 *

Time of day analysis

FF$Session_1_2 <- as.factor(FF$Session_1_2)
FF$time <- as.factor(FF$time)

result <- FF %>%
  group_by(Session_1_2) %>%
  summarize(
    Mean = mean(insight),
    SEM = sd(insight) / sqrt(n()))

ToD<- summary(aov(insight ~ time * Session_1_2, data = FF))
ToD
##                  Df Sum Sq Mean Sq F value  Pr(>F)   
## time              1   0.00   0.000   0.000 1.00000   
## Session_1_2       1   8.64   8.643   9.621 0.00311 **
## time:Session_1_2  1   0.07   0.071   0.080 0.77908   
## Residuals        52  46.71   0.898                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1