While working on the sample size calculation for the PPCR group project, I encountered a problem: one of the papers we were trying to use (D’Silva et al., 2023) did not report the standard deviation (SD) for the primary outcome. Then, when we were trying to calculate the standardized mean difference, we had some trouble. Professor David Wypij then suggested we reverse engineer the SD from the p-value that was reported for the t-test.
During this endeavor, I realized that the function we used in R to obtain the t-statistic from the p-value for this isn’t too intuitive. I then decided to create a new one, based on the already existent functions in base R.
tinv <- function (p, df) {
## this structure is based on the very intuitive inputs that the tinv function
## has in microsoft excel
## we will use the quantile function for t distribution
qt (1-(p/2), df)
## p-value is divided by two, as we're assuming a two-sided t-test
}
Let’s then test this, comparing to a table.
tinv (0.05, 20)
## [1] 2.085963
tinv (0.05, 21)
## [1] 2.079614
tinv (0.02, 20)
## [1] 2.527977
The test shows that the function works properly, as expected.
A simple function, but useful, especially when conducting systematic reviews and meta-analysis.