
Synthesise a dataset from paired-sample t-test summary statistics
Source:R/makePaired.R
makePaired.Rd
makePaired()
generates a dataset from
paired-sample t-test summary statistics.
makePaired()
generates correlated values so the data replicate
rating scales taken, for example, in a before and after experimental design.
The function is effectively a wrapper function for
lfast()
and lcor()
with the addition of a
t-statistic from which the between-column correlation is inferred.
Paired t-tests apply to observations that are associated with each other. For example: the same people before and after a treatment; the same people rating two different objects; ratings by husband & wife; etc.
The t-test for paired data is given by:
t = mean(D) / (sd(D) / sqrt(n))
where:
D = differences in values,
mean(D) = mean of the differences,
sd(D) = standard deviation of the differences, where
sd(D)^2 = sd(X_before)^2 + sd(X_after)^2 - 2 * cov(X_before, X_after)
A paired-sample t-test thus requires an estimate of the covariance between
the two sets of observations.
makePaired()
rearranges these formulae so that the covariance is
inferred from the t-statistic.
Arguments
- n
(positive, integer) sample size
- means
(real) 1:2 vector of target means for two before/after measures
- sds
(real) 1:2 vector of target standard deviations
- t_value
(real) desired paired t-statistic
- lowerbound
(integer) lower bound (e.g. '1' for a 1-5 rating scale)
- upperbound
(integer) upper bound (e.g. '5' for a 1-5 rating scale)
- items
(positive, integer) number of items in the rating scale. Default = 1
- precision
(positive, real) relaxes the level of accuracy required. Default = 0
Note
Larger sample sizes usually result in higher t-statistics, and correspondingly small p-values.
Small sample sizes with relatively large standard deviations and relatively high t-statistics can result in impossible correlation values.
Similarly, large sample sizes with low t-statistics can result in impossible correlations. That is, a correlation outside of the -1:+1 range.
If this happens, the function will fail with an ERROR message. The user should review the input parameters and insert more realistic values.
Examples
n <- 20
pair_m <- c(2.5, 3.0)
pair_s <- c(1.0, 1.5)
lower <- 1
upper <- 5
k <- 6
t <- -2.5
pairedDat <- makePaired(
n = n, means = pair_m, sds = pair_s,
t_value = t,
lowerbound = lower, upperbound = upper, items = k
)
#> Initial data vectors
#> reached maximum of 1024 iterations
#> reached maximum of 1024 iterations
#> Rearrange values to conform with desired t-value
#> Complete!
str(pairedDat)
#> 'data.frame': 20 obs. of 2 variables:
#> $ X1: num 1.17 2.83 2.17 2.17 1.33 ...
#> $ X2: num 1 2.33 1.5 2.83 1 ...
cor(pairedDat) |> round(2)
#> X1 X2
#> X1 1.00 0.82
#> X2 0.82 1.00
t.test(pairedDat$V1, pairedDat$V2, paired = TRUE)
#> Error in t.test.default(pairedDat$V1, pairedDat$V2, paired = TRUE): 'y' is missing for paired test