You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#' This is function let you perform automated inferential testing based on certain assumptions, some of which are tested automatically, then the propper test is perform, giving you an APA formated output with your statistical results.
4
+
#'
5
+
#' @param data Your dataset in long format, can have some missing values.
6
+
#' @param response Response variable, numeric.
7
+
#' @param between Quoted or unquoted variable indicating the between-subject(s) factor(s)/column(s) in data. Default is NULL indicating no between-subjects factors. Must be character vector if more than one between-subject(s) factor(s)/column(s) is specified.
8
+
#' @param within Quoted or unquoted variable indicating the within-subject(s) factor(s)/column(s) in data. Default is NULL indicating no between-subjects factors. Must be character vector if more than one within-subject(s) factor(s)/column(s) is specified.
9
+
#' @param id Quoted or unquoted variable (of length 1) indicating the subject identifier column in data.
10
+
#' @param type The type of sums of squares for the ANOVA. Possible values are "II", "III", 2, or 3 (default).
11
+
#' @param es The effect size used to estimate the effects of the factors on the response variable. Possible values are 'omega' or 'eta' (default).
12
+
#' @param sphericity If `"none"`, then sphericity assumption is assumed to be met for within-subject(s) factor(s). "GG": applies Greenhouse-Geisser correction. "HF": applies Hyunh-Feldt correction. 'auto' (Default) choose the appropiate correction based on Mauchly test of sphericity (p-value > 0.05)
13
+
#' @param markdown Whether you want the output formated for inline R Markdown or as plain text.
14
+
#' @keywords aov_r
15
+
#' @return A list with full statistical results, estimates and simple stats in APA style for each factor and interaction term(s).
16
+
#' @export
17
+
18
+
aov_r<-function(data
19
+
, response
20
+
, between=NULL
21
+
, within=NULL
22
+
, id
23
+
, type=3
24
+
, es='eta'# 'omega' (default) or 'eta'
25
+
, sphericity='auto'# 'auto' (default), 'GG', 'HF' or 'none'
Copy file name to clipboardExpand all lines: README.Rmd
+53-2Lines changed: 53 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -94,11 +94,62 @@ result
94
94
95
95
The core function: `report` by default return a list of length two in Markdown format (as seen before) for inline results. An example using same data as before:
96
96
97
-
The analysis of the effects of the treatment shows an statistically significant difference between the groups, `result$full`, evaluated through `result$method`.
97
+
> The analysis of the effects of the treatment shows an statistically significant difference between the groups, `result$full`, evaluated through `result$method`.
98
98
99
99
translates into this:
100
100
101
-
The analysis of the effects of the treatment shows an statistically significant difference between the groups, *t* <sub>Student</sub> (98) = 2.509, *p* = 0.014, *d* <sub>Cohen's</sub> = 0.51, IC<sub>95%</sub> [0.1, 0.91], evaluated through Student's t-test for independent samples.
101
+
> The analysis of the effects of the treatment shows an statistically significant difference between the groups, *t* <sub>Student</sub> (98) = 2.509, *p* = 0.014, *d* <sub>Cohen's</sub> = 0.51, CI<sub>95%</sub>[0.1, 0.91], evaluated through Student's t-test for independent samples.
102
+
103
+
## Mixed effects ANOVA
104
+
105
+
By using `aov_r` function is possible to get the statistical report of between/within-subject(s) factor(s) for factorial designs using `afex` package under the hood for statistical reporting. Let's see an example
# Manipulate data to generate interaction between Gender and Time
121
+
Stroop <- within(Stroop, {
122
+
Score[Gender == 'Male' & Time == 1] <- Score[Gender == 'Male' & Time == 1]*1
123
+
Score[Gender == 'Male' & Time == 2] <- Score[Gender == 'Male' & Time == 2]*1.15
124
+
Score[Gender == 'Male' & Time == 3] <- Score[Gender == 'Male' & Time == 3]*1.3
125
+
Score[Gender == 'Female' & Time == 1] <- Score[Gender == 'Female' & Time == 1]*1
126
+
Score[Gender == 'Female' & Time == 2] <- Score[Gender == 'Female' & Time == 2]*0.85
127
+
Score[Gender == 'Female' & Time == 3] <- Score[Gender == 'Female' & Time == 3]*0.7
128
+
})
129
+
130
+
131
+
r <- aov_r(
132
+
data = Stroop
133
+
, response = Score
134
+
, between = Gender
135
+
, within = Time
136
+
, id = Subject
137
+
, es = 'omega' # omega squared as our measure of effect size
138
+
, sphericity = 'auto' # check if sphericity is not being violated
139
+
)
140
+
141
+
r
142
+
```
143
+
144
+
For inline results with previous data we would do something like this:
145
+
146
+
> In order to analyze the effect of gender on subjects' scores in each of the evaluation periods, we performed an analysis of variance (ANOVA) with between- and within-subjects factors. From the analyses, we find that gender has a large effect ( `r$es$Gender` ) on scores when adjusting for each of the time periods, `r$stats$Gender`. In a similar way we find a significant interaction between evaluative time and gender ( `r$stats$Gender_Time` ), indicating unequal responses between males and females over time, `r$es$Gender_Time`, however, time alone is not able to explain statistically significantly the variance in scores, `r$full$Time`.
147
+
148
+
Which will translate into this after evaluation in R Markdown:
149
+
150
+
> In order to analyze the effect of gender on subjects' scores in each of the evaluation periods, we performed an analysis of variance (ANOVA) with between- and within-subjects factors. From the analyses, we find that gender has a large effect ( 𝜔<sup>2</sup> = 0.63, CI<sub>95%</sub>[0.58, 0.67] ) on scores when adjusting for each of the time periods, *F* <sub>Fisher</sub> (1, 398) = 682.91, *p* < 0.001. In a similar way we find a significant interaction between evaluative time and gender ( *F* <sub>Fisher</sub> (2, 796) = 223.68, *p* < 0.001 ), indicating unequal responses between males and females over time, 𝜔<sup>2</sup> = 0.27, CI<sub>95%</sub>[0.22, 0.32], however, time alone is not able to explain statistically significantly the variance in scores, *F* <sub>Fisher</sub> (2, 796) = 0.11, *p* = 0.894, 𝜔<sup>2</sup> = 0, CI<sub>95%</sub>[0, 0].
151
+
152
+
When you have more than 1 factor (between or within subjects) you have to specify them a character vector: `between = c('factor1', 'factor2' ...)`, and the same for `within = c('factor1', 'factor2' ...)`.
Copy file name to clipboardExpand all lines: README.md
+92-5Lines changed: 92 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
1
2
# writR: Inferential statistics and reporting in APA style
2
3
3
4
For automated and basic inferential testing.
@@ -25,7 +26,7 @@ citation('writR')
25
26
## To cite package 'writR' in publications use:
26
27
##
27
28
## Matías Castillo Aguilar (2021). writR: Inferential statistics and
28
-
## reporting in APA style. R package version 0.0.1.
29
+
## reporting in APA style. R package version 0.1.1.
29
30
## https://github.com/matcasti/writR
30
31
##
31
32
## A BibTeX entry for LaTeX users is
@@ -34,7 +35,7 @@ citation('writR')
34
35
## title = {writR: Inferential statistics and reporting in APA style},
35
36
## author = {Matías {Castillo Aguilar}},
36
37
## year = {2021},
37
-
## note = {R package version 0.0.1},
38
+
## note = {R package version 0.1.1},
38
39
## url = {https://github.com/matcasti/writR},
39
40
## }
40
41
```
@@ -122,11 +123,97 @@ result
122
123
123
124
The core function: `report` by default return a list of length two in Markdown format (as seen before) for inline results. An example using same data as before:
124
125
125
-
The analysis of the effects of the treatment shows an statistically significant difference between the groups, `result$full`, evaluated through `result$method`.
126
+
> The analysis of the effects of the treatment shows an statistically significant difference between the groups, `result$full`, evaluated through `result$method`.
126
127
127
128
translates into this:
128
129
129
-
The analysis of the effects of the treatment shows an statistically significant difference between the groups, *t* <sub>Student</sub> (98) = 2.509, *p* = 0.014, *d* <sub>Cohen's</sub> = 0.51, IC<sub>95%</sub> [0.1, 0.91], evaluated through Student's t-test for independent samples.
130
+
> The analysis of the effects of the treatment shows an statistically significant difference between the groups, *t* <sub>Student</sub> (98) = 2.509, *p* = 0.014, *d* <sub>Cohen's</sub> = 0.51, CI<sub>95%</sub>[0.1, 0.91], evaluated through Student's t-test for independent samples.
131
+
132
+
## Mixed effects ANOVA
133
+
134
+
By using `aov_r` function is possible to get the statistical report of between/within-subject(s) factor(s) for factorial designs using `afex` package under the hood for statistical reporting. Let's see an example
135
+
136
+
137
+
```r
138
+
# set parameters to simulate data with a between and within subject factor
For inline results with previous data we would do something like this:
209
+
210
+
> In order to analyze the effect of gender on subjects' scores in each of the evaluation periods, we performed an analysis of variance (ANOVA) with between- and within-subjects factors. From the analyses, we find that gender has a large effect ( `r$es$Gender` ) on scores when adjusting for each of the time periods, `r$stats$Gender`. In a similar way we find a significant interaction between evaluative time and gender ( `r$stats$Gender_Time` ), indicating unequal responses between males and females over time, `r$es$Gender_Time`, however, time alone is not able to explain statistically significantly the variance in scores, `r$full$Time`.
211
+
212
+
Which will translate into this after evaluation in R Markdown:
213
+
214
+
> In order to analyze the effect of gender on subjects' scores in each of the evaluation periods, we performed an analysis of variance (ANOVA) with between- and within-subjects factors. From the analyses, we find that gender has a large effect ( 𝜔<sup>2</sup> = 0.63, CI<sub>95%</sub>[0.58, 0.67] ) on scores when adjusting for each of the time periods, *F* <sub>Fisher</sub> (1, 398) = 682.91, *p* < 0.001. In a similar way we find a significant interaction between evaluative time and gender ( *F* <sub>Fisher</sub> (2, 796) = 223.68, *p* < 0.001 ), indicating unequal responses between males and females over time, 𝜔<sup>2</sup> = 0.27, CI<sub>95%</sub>[0.22, 0.32], however, time alone is not able to explain statistically significantly the variance in scores, *F* <sub>Fisher</sub> (2, 796) = 0.11, *p* = 0.894, 𝜔<sup>2</sup> = 0, CI<sub>95%</sub>[0, 0].
215
+
216
+
When you have more than 1 factor (between or within subjects) you have to specify them a character vector: `between = c('factor1', 'factor2' ...)`, and the same for `within = c('factor1', 'factor2' ...)`.
0 commit comments