library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.2     v dplyr   1.0.6
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library(dplyr)
library(crunch)
## 
## Attaching package: 'crunch'
## The following objects are masked from 'package:dplyr':
## 
##     combine, filter, id
## The following object is masked from 'package:ggplot2':
## 
##     resolution
## The following objects are masked from 'package:stats':
## 
##     filter, rstandard, setNames
## The following object is masked from 'package:graphics':
## 
##     title
## The following object is masked from 'package:utils':
## 
##     write.csv
## The following object is masked from 'package:base':
## 
##     table
library(remotes)
install_github("JanMarvin/readspss")
## Skipping install of 'readspss' from a github remote, the SHA1 (bbc71e6b) has not changed since last install.
##   Use `force = TRUE` to force installation
library(readr)
replicationdata <- read_csv("~/Coding-R/replication project/replicationdata.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   ParticipantID = col_character(),
##   General_1_MedList = col_character(),
##   General_1_University = col_character()
## )
## i Use `spec()` for the full column specifications.
View(replicationdata)

#loading data

Excluding participants from data

cleandata <- replicationdata %>% # removing participants who were excluded 
  filter(exclude==0)

Calculating age

ageaverage <- cleandata %>% #calculating average age including sd using cleaned data
  select(General_1_Age) %>%
  summarise(ageaverage = mean(General_1_Age), 
          agesd = sd(General_1_Age))


print(ageaverage)
## # A tibble: 1 x 2
##   ageaverage agesd
##        <dbl> <dbl>
## 1       19.5  1.23

Trying to find average ESS score

ESS <- cleandata %>% 
  select(Epworth_total) %>% 
  summarise(ESS = mean(Epworth_total), ESSSD = sd(Epworth_total))

print(ESS)
## # A tibble: 1 x 2
##     ESS ESSSD
##   <dbl> <dbl>
## 1  15.3  2.83

Trying to find SSS score

SSSgroup <- cleandata %>% 
  select(AlertTest_1_Feel, 
         AlertTest_2_Feel, 
         AlertTest_3_Feel, 
         AlertTest_4_Feel) %>% 
  drop_na() %>% 
    summarise(
    AT1F = mean(AlertTest_1_Feel),
    AT2F = mean(AlertTest_2_Feel),
    AT3F = mean(AlertTest_3_Feel),
    AT4F = mean(AlertTest_4_Feel)
    )

SSS <- SSSgroup %>% 
  summarise(SSSav = mean(SSSgroup))
## Warning in mean.default(SSSgroup): argument is not numeric or logical: returning
## NA
print(SSS)
## # A tibble: 1 x 1
##   SSSav
##   <dbl>
## 1    NA

Attepting merge function: unsuccessful

SSStotal <- cleandata %>% 
   select(AlertTest_1_Feel, 
         AlertTest_2_Feel, 
         AlertTest_3_Feel, 
         AlertTest_4_Feel) %>% 
  merge(AlertTest_1_Feel, AlertTest_2_Feel, AlertTest_3_Feel, AlertTest_4_Feel, by=participantID)

print(SSStotal)

attempting to use bind function: successful but not right value

SSS <- cleandata %>% 
  select(AlertTest_1_Feel, 
         AlertTest_2_Feel, 
         AlertTest_3_Feel, 
         AlertTest_4_Feel) %>% 
  drop_na() %>% 
  summarise( mean( rbind(AlertTest_1_Feel, AlertTest_2_Feel, AlertTest_3_Feel, AlertTest_4_Feel)))

print(SSS)
## # A tibble: 1 x 1
##   `mean(...)`
##         <dbl>
## 1        2.69

Applying above to not tweaked data (ignoring exclusions) - not right value

SSStrial <- replicationdata %>% 
  select(AlertTest_1_Feel, 
         AlertTest_2_Feel, 
         AlertTest_3_Feel, 
         AlertTest_4_Feel) %>% 
  drop_na() %>% 
  summarise( mean( rbind(AlertTest_1_Feel, AlertTest_2_Feel, AlertTest_3_Feel, AlertTest_4_Feel)))

print(SSStrial)
## # A tibble: 1 x 1
##   `mean(...)`
##         <dbl>
## 1        2.62