View source: R/draw_sample_n.R
draw_sample_n | R Documentation |
A Function to sample data close to desired characteristics - nearest
draw_sample_n( dist, n, skew, kurts, location = 0, delta_var = 0, save.output = FALSE, output_name = c("sample", "default") )
dist |
data frame:consists of id and scores with no missing |
n |
numeric: desired sample size |
skew |
numeric: the skewness value |
kurts |
numeric: the kurtosis value |
location |
numeric: the value for adjusting mean (default is 0). |
delta_var |
numeric: the value for adjusting variance (default is 0). |
save.output |
logical: should the output be saved into a text file? (Default is FALSE). |
output_name |
character: a vector of two components. The first component is the name of the output file, user can change the second component. |
The desired skewness and kurtosis values cannot be met while the function
execution is faster. The attributes of kurtosis are in doubt.
This is because the range of kurtosis is greater than the skewness.
For location
values can be entered to position the midpoint or mean of the
distribution differently. For delta_var
the value can be entered for
how much will increase or decrease the variability of reference distribution.
In other words, the reference distribution is generated as the standard normal distribution,
unless the user changes the default values of the location
and delta_var
arguments.
This function returns a list
including following:
a matrix: Descriptive statistics of the given data, the reference vector and the sample.
a data frame: The id's and scores of the sample
graph: Histograms for the “data” and the “sample”
Fleishman AI (1978). A Method for Simulating Non-normal Distributions. Psychometrika, 43, 521-532. doi: 10.1007/BF02293811.
Fialkowski, A. C. (2018). SimMultiCorrData: Simulation of Correlated Data with Multiple #' Variable Types. R package version 0.2.2. Retrieved from https://cran.r-project.org/web/packages/SimMultiCorrData/index.html
# Example data provided with package data(example_data) # Draw a sample based on Score_1 output2 <- draw_sample_n(dist=example_data[,c(1,2)],n=200,skew = 0, kurts = 0, location=0, delta_var=0,save.output=FALSE) # Histogram of the reference data set # descriptive statistics of the given data,reference data, and drawn sample output2$desc # First 6 rows of the drawn sample head(output2$sample) # Histogram of the given data set and drawn sample output2$graph ## Not run: # Draw a sample based on Score_2 (location par) # draw_sample_n(dist=example_data[,c(1,3)],n=200,skew = 1,kurts = 1,location=-0.5,delta_var=0, # save.output=TRUE, output_name = c("sample", "2")) # Draw a sample based on Score_2 (delta_var par) # draw_sample_n(dist=example_data[,c(1,3)],n=200,skew = 0.5,kurts = 0.4,location=0,delta_var=0.3, # save.output=TRUE, output_name = c("sample", "3")) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.