-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
133 lines (92 loc) · 2.16 KB
/
README.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(scipen = 999, digits = 5)
```
# criticalESvalue
<!-- badges: start -->
<!-- badges: end -->
The goal of criticalvalue is to ...
<!-- TODO aggiungi qualche riga qui -->
## Installation
You can install the development version of criticalESvalue like so:
``` r
# require(remotes)
remotes::install_github("psicostat/criticalESvalue")
```
## Examples
```{r}
# loading the package
library(criticalESvalue)
```
### T Test
```{r example}
# t-test (welch)
x <- rnorm(30, 0.5, 1)
y <- rnorm(30, 0, 1)
ttest <- t.test(x, y)
critical(ttest)
# t-test (standard)
ttest <- t.test(x, y, var.equal = TRUE)
critical(ttest)
# t-test (standard) with monodirectional hyp
ttest <- t.test(x, y, var.equal = TRUE, alternative = "less")
critical(ttest)
# within the t-test object saved from critical we have all the new values
ttest <- critical(ttest)
str(ttest)
```
We can check the results using:
```{r}
ttest <- t.test(x, y)
ttest <- critical(ttest)
t <- ttest$bc/ttest$stderr # critical numerator / standard error
# should be 0.05 (or alpha)
(1 - pt(ttest$bc/ttest$stderr, ttest$parameter)) * 2
```
### Correlation Test
```{r}
# cor.test
ctest <- cor.test(x, y)
critical(ctest)
```
### Linear Model
```{r}
# linear model (unstandardized)
z <- rnorm(30)
q <- rnorm(30)
dat <- data.frame(x, y, z, q)
fit <- lm(y ~ x + q + z, data = dat)
fit <- critical(fit)
fit
summary(fit)
```
### Meta-analysis
```{r}
library(metafor)
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
fit <- rma(yi, vi, mods=cbind(ablat, year), data=dat)
critical(fit)
```
## Example from summary statistics
```{r}
x <- rnorm(30, 0.5, 1)
y <- rnorm(30, 0, 1)
ttest <- t.test(x, y)
m1 <- mean(x)
m2 <- mean(y)
sd1 <- sd(x)
sd2 <- sd(y)
n1 <- n2 <- 30
critical_t2s(m1, m2, sd1 = sd1, sd2 = sd2, n1 = n1, n2 = n2)
critical_t2s(t = ttest$statistic, se = ttest$stderr, n1 = n1, n2 = n2)
critical_t2s(t = ttest$statistic, n1 = n1, n2 = n2)
```