Description Usage Arguments Value Note Author(s) Examples
stat.gen is a function to generate raw data based on user-specified descriptive statistics (n, mean, & standard deviation). A sample of N scores will be drawn from an appropriate distribution (normal or exponential) and scaled to match the desired mean and standard deviation. The raw data will be written to a text file in the user's working directory.
1 |
num.subj |
Specifies the intended sample size (n) |
target.mean |
Specifies the intended sample mean |
target.sd |
Specifies the intended sample standard deviation |
data.dec |
Specifies the number of decimal places in the sample data |
neg.data |
Specifies whether the sample data can include negative values |
x.name |
Specifies the name of the variable |
The values returned are the raw data which is printed to the R console as well as saved to a text file to be imported to other programs or back into R. The R console will also display performance data including the descriptive statistics and the number of iterations needed to find a solution.
For most applications, stat.gen will be able to generate a succesful dataset. However, recognize that the raw data may look more or less like you would expect the original raw data to look given that an infinite combination of values could emulate any of the supplied descriptive statistics. Modifying the data.dec command and/or the neg.data command can help the generated raw data look more realistic.
If neg.data=FALSE (i.e., the raw data cannot be negative), and the target mean is near zero (i.e., the sample is positively skewed with a floor effect at 0), stat.gen will draw scores from an exponential distribution to facilitate finding a solution.
Brendan Morse
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 | # In a study published in Body Image on the
# effects of massage on state (temporary) body
# image, Dunigan, King, & Morse (2011) that there
# were no significant differences in body mass
# index scores (BMI) between the control (n=26,
# M=25.26, SD=6.51) and experimental (n=23, M=23.30,
# SD=5.83) conditions as a check for potential confounds.
# We can use MorseGen to generate a sample of raw scores
# to match these statistics and use this data as a
# teaching example for an independent samples t-test in an
# introductory statistics course.
# Generate the control group data.
# I set non.neg=TRUE because the supplied descriptive
# statistics could return a negative value (0 is within 4 standard
# deviations from each mean) and BMI cannot be negative.
# Note that the output file "MorseGen Sample Results.txt" will
# overwrite the data with each run of the stat.gen function so
# the scores must be copied out or saved as a different file name
# after each run.
stat.gen(26, 25.26, 6.51, data.dec=2, neg.data=FALSE, x.name="Control")
#To generate the experimental group data
stat.gen(23, 23.30, 5.83, data.dec=2, neg.data=FALSE, x.name="Massage")
|
working on iteration 1
working on iteration 2
working on iteration 3
working on iteration 4
working on iteration 5
Summary of the Simulation Results (note: raw data has been exported to the file: Control MorseGen Results.txt in your working directory )
$DATA
Control
[1,] 32.31
[2,] 34.30
[3,] 29.26
[4,] 26.66
[5,] 14.17
[6,] 13.41
[7,] 32.47
[8,] 31.23
[9,] 14.34
[10,] 25.58
[11,] 22.10
[12,] 21.50
[13,] 24.55
[14,] 32.55
[15,] 27.24
[16,] 36.21
[17,] 19.75
[18,] 30.38
[19,] 26.53
[20,] 17.59
[21,] 23.25
[22,] 26.17
[23,] 17.25
[24,] 21.57
[25,] 24.92
[26,] 31.46
$PERFORMANCE
Target Control Mean Sample Control Mean Target Control SD Sample Control SD
1 25.26 25.2596 6.51 6.5102
Iterations
1 5
working on iteration 1
Summary of the Simulation Results (note: raw data has been exported to the file: Massage MorseGen Results.txt in your working directory )
$DATA
Massage
[1,] 25.90
[2,] 30.98
[3,] 24.81
[4,] 14.92
[5,] 15.51
[6,] 19.78
[7,] 21.37
[8,] 28.61
[9,] 18.51
[10,] 25.33
[11,] 18.02
[12,] 35.95
[13,] 21.49
[14,] 20.41
[15,] 22.04
[16,] 16.39
[17,] 20.24
[18,] 33.80
[19,] 27.88
[20,] 22.88
[21,] 21.23
[22,] 18.66
[23,] 31.18
$PERFORMANCE
Target Massage Mean Sample Massage Mean Target Massage SD Sample Massage SD
1 23.3 23.2996 5.83 5.8304
Iterations
1 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.