-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path04_omegaPLoR.Rmd
80 lines (60 loc) · 2.1 KB
/
04_omegaPLoR.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: "04_omegaPLoR"
output: html_document
---
__Code written:__ 2019-12-02
__Last run:__ `r Sys.Date()`
__Authors:__ Navona Calarco
__Website:__ https://rpubs.com/navona/Mar_categoricalOmegaReading
__Git repo:__ https://github.com/navonacalarco/NRC_Mar
```{r setup}
#clean environment
rm(list = ls(all.names = TRUE))
#set working directory
knitr::opts_knit$set(root.dir = '../data/out/PLoR')
```
```{r}
#libraries
library('MBESS')
library('dplyr')
#read in all PLoR csvs
all_dfs = list.files(pattern="*.csv")
for (i in 1:length(all_dfs)) assign(all_dfs[i], read.csv(all_dfs[i]))
#fn for omega -- hierarchical as 7 levels
omega_fn <- function(df){
ci.reliability(df, type='hierarchical', interval.type = 'bca', B=1000, conf.level=.95 )
}
#apply fn to all PLoR dfs -- results will have same name
cCmd <- paste(all_dfs , "<- omega_fn(" ,all_dfs,")", sep="")
eCmd <- parse(text=cCmd)
eval(eCmd)
```
```{r calculations for table}
#write fn to find missing values -- and replace with average of participant's scores score
replaceMissing_fn <- function(df){
df <- as.matrix(df)
missing <- which(is.na(df), arr.ind=TRUE)
df[missing] <- rowMeans(df, na.rm=TRUE)[missing[,1]]
df <- as.data.frame(df)
}
#apply fn to all PLoR dfs -- results will have same name
cCmd <- paste(all_dfs , "<- replaceMissing_fn(" ,all_dfs,")", sep="")
eCmd <- parse(text=cCmd)
eval(eCmd)
#row sums function
rowSums_fn = function(df){
df = mutate(df, total=rowSums(df))
return(df)
}
#apply fn to all PLoR dfs -- results will have same name
cCmd <- paste(all_dfs , "<- rowSums_fn(" ,all_dfs,")", sep="")
eCmd <- parse(text=cCmd)
eval(eCmd)
#turn all dataframes into a list
df.list <- Filter(function(x) is(x, "data.frame"), mget(ls()))
#for each dataframe in the list:
means <- t(as.data.frame(lapply(df.list, function (x) mean(x[,'total'], na.rm= TRUE))))
sds <- t(as.data.frame(lapply(df.list, function (x) sd(x[,'total'], na.rm= TRUE))))
min <- t(as.data.frame(lapply(df.list, function (x) min(x[,'total'], na.rm= TRUE))))
max <- t(as.data.frame(lapply(df.list, function (x) max(x[,'total'], na.rm= TRUE))))
```