Skip to contents

To install the package the following line of code is needed:

# require(devtools)
devtools::install_github("filippogambarota/criticalvalue")
library(criticalESvalue)

Examples on real data

For our examples on real data we used from the package ‘psych’ the dataset “holzinger.swineford” which has a series of demographics and scores of different subtests measuring intelligence on 301 subjects. Once the package is retrieved with ‘library’, the dataset can be opened using ‘data(“name of the dataset”)’. For simplicity we decided to rename it with a shorter name.

data("holzinger.swineford")
Holz <- holzinger.swineford

Critical value for correlation

In the following chunk we want to get the critical value for a correlation of two cognitive sub-tests of 301 subjects. We can do so with the ‘critical’ function:

cc <- cor.test(Holz$t01_visperc, Holz$t02_cubes)
critical(cc)
#> 
#>  Pearson's product-moment correlation
#> 
#> data:  Holz$t01_visperc and Holz$t02_cubes
#> t = 5.3852, df = 299, p-value = 1.467e-07
#> alternative hypothesis: true correlation is not equal to 0
#> 95 percent confidence interval:
#>  0.1907064 0.3970530
#> sample estimates:
#>       cor 
#> 0.2973479 
#> 
#> |== Critical Value ==| 
#> |rc| = 0.1130784

First, the ‘cor.test’ function should be used on the two variables of interest and then the newly created object should be put into the ‘critical’ function. The output will add, underneath the usual output of the ‘cor.test’ function, the absolute critical value (rc), representing the smallest significant effect.

Critical value for t-test

Now we want to know the critical value for a t-test comparing boys and girls on a cognitive variable of visual perception. In this case, it can be easily done with the same procedure using the ‘t.test’ function:

tt <- t.test(Holz$t01_visperc [ Holz$female == 1], Holz$t01_visperc [ Holz$female == 2])
critical(tt)
#> 
#>  Welch Two Sample t-test
#> 
#> data:  Holz$t01_visperc[Holz$female == 1] and Holz$t01_visperc[Holz$female == 2]
#> t = 1.4095, df = 298.9, p-value = 0.1597
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  -0.06419229  0.38823118
#> sample estimates:
#> mean of x mean of y 
#>  4.314090  4.152071 
#> 
#> |== Effect Size and Critical Value ==| 
#> d = 0.1623665 dc = ± 0.2269609 bc = ± 0.2262117 
#> g = 0.1619587 gc = ± 0.2263909

The output now gives a wider range of values: the cohen’s d calculated on the data (d), the critical cohen’s d (dc), the numerator of the formula for the critical cohen’s d (bc), the cohen’s d adjusted for small samples (g) and the critical cohen’s d adjusted for small samples (gc).

Critical value for linear model

Now we want to calculate the critical coefficients for a linear model with visual perception predicted by age. We can do so by wrapping the ‘critical’ function into the ‘summary’ function:

ll <- lm( t01_visperc ~ ageyr , data = Holz)
summary(critical(ll))
#> 
#> Call:
#> lm(formula = t01_visperc ~ ageyr, data = Holz)
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -3.6019 -0.6591 -0.0019  0.6266  3.1124 
#> 
#> Coefficients:
#>             Estimate |Critical Estimate| Std. Error t value Pr(>|t|)    
#> (Intercept)  4.97325             1.41113    0.71706   6.936 2.51e-11 ***
#> ageyr       -0.05714             0.10822    0.05499  -1.039      0.3    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 1.001 on 299 degrees of freedom
#> Multiple R-squared:  0.003597,   Adjusted R-squared:  0.0002647 
#> F-statistic: 1.079 on 1 and 299 DF,  p-value: 0.2997

In the output, a column will appear next to the usual column of the estimates reporting critical values for both the intercept and the predictor(s).

Examples with sample size

In the next examples we will show the use of the package’s functions to calculate critical values in a prospective framework.

Critical t value from sample size

Let us say that we want to calculate the critical t value for a t-test for a sample of 1200 subjects for each group, the following chunk shows how to do so with the function ‘critical_t2s’:

n <- 1200
critical_t2s(n1 = n , n2 = n , hypothesis = "less")
#> Warning in crit_from_t_t2s(t = t, n1 = n1, n2 = n2, se = se, conf.level =
#> conf.level, : When var.equal = FALSE the critical value calculated from t
#> assume sd1 = sd2!
#> Warning in crit_from_t_t2s(t = t, n1 = n1, n2 = n2, se = se, conf.level =
#> conf.level, : When t is NULL, d cannot be computed, returning NA
#> Warning in crit_from_t_t2s(t = t, n1 = n1, n2 = n2, se = se, conf.level =
#> conf.level, : When se = NULL bc cannot be computed, returning NA!
#> $d
#> [1] NA
#> 
#> $dc
#> [1] 0.06717682
#> 
#> $bc
#> [1] NA
#> 
#> $se
#> NULL
#> 
#> $df
#> [1] 2398
#> 
#> $gc
#> [1] 0.06715581

The function requires to specify the hypothesis as “less”, “greater” or “two.tailed”. In output we can find the critical d and the critical g, which is the cohen’s d adjusted for small samples.

Critical t value from sample size for a paired t-test.

Assuming that we want to calculate the critical value for a paired t-test (i.e. pre-post treatment), we can do so with the function ‘critical_t2sp’ in the following way:

n <- 15
critical_t2sp(n = n , hypothesis = "less", conf.level = .95)
#> Warning in crit_from_t_t2sp(t = t, n = n, se = se, r12 = r12, hypothesis =
#> hypothesis, : when t is NULL, dz and d cannot be computed, returning NA
#> Warning in crit_from_t_t2sp(t = t, n = n, se = se, r12 = r12, hypothesis =
#> hypothesis, : When se is NULL, bc cannot be computed, returning NA
#> $dz
#> [1] NA
#> 
#> $dzc
#> [1] 0.4547683
#> 
#> $d
#> [1] NA
#> 
#> $dc
#> [1] 0.6431395
#> 
#> $bc
#> [1] NA
#> 
#> $se
#> NULL
#> 
#> $df
#> [1] 14
#> 
#> $gc
#> [1] 0.6079519
#> 
#> $gzc
#> [1] 0.4298869

Specifying the direction of the hypothesis and the confidence interval, the function will give as output the standardized (dzc) and un-standardized (dc) critical cohen’s d, and the critical cohen’s d adjusted for small samples both standardized (gc) and un-standardized (gzc).

Critical value for a correlation from sample size

The same can be done for the critical value for a correlation on a defined sample size with the ‘critical_cor’ function:

n <- 60
critical_cor(n = n, hypothesis = "two.sided", test = "z")
#> $rc
#> [1] 0.2539247
#> 
#> $rzc
#> [1] 0.2596036
#> 
#> $df
#> [1] 58
#> 
#> $se_r
#> numeric(0)
#> 
#> $se_rc
#> [1] 0.1270027
#> 
#> $se_rzc
#> [1] 0.1324532
#> 
#> $test
#> [1] "z"

Once more, the direction of the hypothesis and the test to apply, either t-test or z-test, should be specified. The output will return the critical correlation value, the degrees of freedom and the type of test used.

Critical value of a beta from a model from saple size

Let us say that we want to know the critical beta of a model, we can use the ‘critical_coef’ function as shown in the following chunk:

n <- 170
critical_coef(seb = .1, n = n, p = .01, conf.level = .95, hypothesis = "less")
#> $bc
#> [1] 0.165392
#> 
#> $test
#> [1] "t"

It is important to specifying sample size, standard error of the estimate, p-value, confidence level and hypothesis. The output will return the critical beta and the test used.