From 6b7edcfcdde34dcde45290438e7f1345bd4bee81 Mon Sep 17 00:00:00 2001 From: Marko Lalovic Date: Fri, 26 Jul 2024 14:31:38 +0200 Subject: [PATCH] exported estimate_mean_and_sd, incremented package version to 1.2.2 --- docs/pkgdown.yml | 2 +- docs/reference/estimate_mean_and_sd.html | 11 ++++++++++- docs/search.json | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 8f15256..3530306 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.0.9 pkgdown_sha: ~ articles: using_latent2likert: using_latent2likert.html -last_built: 2024-07-26T10:20Z +last_built: 2024-07-26T12:30Z urls: reference: https://markolalovic.github.io/latent2likert/reference article: https://markolalovic.github.io/latent2likert/articles diff --git a/docs/reference/estimate_mean_and_sd.html b/docs/reference/estimate_mean_and_sd.html index 26efa29..e00e943 100644 --- a/docs/reference/estimate_mean_and_sd.html +++ b/docs/reference/estimate_mean_and_sd.html @@ -66,7 +66,7 @@

Usage

Arguments

prob
-

vector of probabilities for each response category.

+

named vector of probabilities for each response category.

n_levels
@@ -101,6 +101,15 @@

Details

+
+

Examples

+
prob <- c("1" = 0.313, "2" = 0.579, "3" = 0.105, "4" = 0.003)
+# returns estimates that are close to the actual mean and sd: c(-1, 0.5)
+estimate_mean_and_sd(prob, 5)
+#> [1] -1.0025695  0.5004155
+
+
+
diff --git a/docs/search.json b/docs/search.json index dc69782..e36d22f 100644 --- a/docs/search.json +++ b/docs/search.json @@ -1 +1 @@ -[{"path":"https://markolalovic.github.io/latent2likert/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 Marko Lalovic Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Using latent2likert","text":"social sciences, variables interest often conceptualized latent variables — hidden continuous variables measured Likert scale questions, typically categorized Strongly disagree, Disagree, Neutral, Agree, Strongly agree. Researchers frequently aim uncover latent variables using various statistical techniques. Accurate modeling survey data essential comparative analysis simulation. latent2likert package addresses need providing effective algorithm simulate Likert response variables hypothetical latent variables. vignette provides two practical workflow examples demonstrating use latent2likert package.","code":""},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"simulating-survey-data","dir":"Articles","previous_headings":"","what":"Simulating Survey Data","title":"Using latent2likert","text":"following hypothetical survey simulation loosely based actual comparative study teaching learning R pair introductory statistics labs (McNamara 2024). Imagine situation 10 participants Course 20 participants Course B completed survey. Suppose initial question : “rate experience course?” four possible answers: Poor, Fair, Good, Excellent. Let’s assume participants Course neutral regarding question, participants Course B positive experience average. choosing appropriate parameters latent distributions setting number categories n_levels = 4, can generate hypothetical responses (standard deviation sd = 1 skewness skew = 0, default): summarize results, create data frame responses: results can visualized using grouped bar chart:","code":"library(latent2likert) # Load the package set.seed(12345) # Ensure reproducible results # Generate responses for Course A and Course B responses_A <- rlikert(size = 10, n_items = 1, n_levels = 4, mean = 0, sd = 1) responses_B <- rlikert(size = 20, n_items = 1, n_levels = 4, mean = 1, sd = 1) n_levels <- 4 n_groups <- 2 categories <- c(\"Poor\", \"Fair\", \"Good\", \"Excellent\") # Create a data frame to summarize the responses response_data <- data.frame( Course = rep(c(\"A\", \"B\"), each = n_levels), Response = factor(rep(categories, n_groups), levels = categories), Proportion = c( response_prop(responses_A, n_levels), response_prop(responses_B, n_levels) ) ) # Filter out rows with zero proportions response_data <- response_data[response_data$Proportion > 0, ] response_data #> Course Response Proportion #> 1 A Poor 0.30 #> 2 A Fair 0.20 #> 3 A Good 0.20 #> 4 A Excellent 0.30 #> 6 B Fair 0.10 #> 7 B Good 0.25 #> 8 B Excellent 0.65"},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"pre-and-post-comparison","dir":"Articles","previous_headings":"","what":"Pre and Post Comparison","title":"Using latent2likert","text":"Now suppose survey also asked participants rate skills 5-point Likert scale, ranging 1 (poor) 5 (good) : Programming, Searching Online, Solving Problems. survey completed participants taking course pre post-comparison. Suppose participants’ assessments : Programming skills average increased, Searching Online stayed , Solving Problems increased Course , decreased participants Course B. Let’s simulate survey data scenario: Create data frame responses summarize results: visualize results stacked bar chart:","code":"# Pre- and post-assessments of skills for Course A pre_A <- rlikert(size = 10, n_items = 3, n_levels = 5, mean = c(-1, 0, 1)) post_A <- rlikert(size = 10, n_items = 3, n_levels = 5, mean = c(0, 0, 2)) # Pre- and post-assessments of skills for Course B pre_B <- rlikert(size = 20, n_items = 3, n_levels = 5, mean = c(-1, 0, 1)) post_B <- rlikert(size = 20, n_items = 3, n_levels = 5, mean = c(0, 0, 0)) # Combine pre and post responses into a list pre_post <- list(pre_A, post_A, pre_B, post_B) # Number of items and response levels n_items <- 3 n_levels <- 5 # Define skills assessed skills <- c(\"Programming\", \"Searching online\", \"Solving problems\") # Generate repeated skill labels for questions questions <- rep(rep(skills, each = n_levels), 4) questions <- factor(questions, levels = skills) # Create a data frame to summarize the responses response_data <- data.frame( Course = rep(c(\"Course A\", \"Course B\"), each = 2 * n_items * n_levels), Question = questions, Time = as.factor(rep(c( rep(\"before\", n_items * n_levels), rep(\"after\", n_items * n_levels) ), 2)), Response = rep(seq_len(n_levels), 2 * n_items * 2), Proportion = as.vector(sapply(pre_post, function(d) { as.vector(t(response_prop(d, n_levels))) })) ) head(response_data) #> Course Question Time Response Proportion #> 1 Course A Programming before 1 0.5 #> 2 Course A Programming before 2 0.2 #> 3 Course A Programming before 3 0.3 #> 4 Course A Programming before 4 0.0 #> 5 Course A Programming before 5 0.0 #> 6 Course A Searching online before 1 0.1"},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"recreating-scale-scores","dir":"Articles","previous_headings":"","what":"Recreating Scale Scores","title":"Using latent2likert","text":"use part bfi data set (Revelle 2024). Specifically, ’ll focus first 5 items corresponding agreeableness. investigate differences agreeableness men women, ’ll also use gender attribute. Load data: Separate items two groups according gender: Estimate parameters latent variables, assuming normal providing number possible response categories n_levels = 6: Generate new responses items using estimated parameters estimated correlations: Create agreeableness scale scores groups participants taking average 5 items: results can visualized grouped boxplot:","code":"data(part_bfi) head(part_bfi) #> A1 A2 A3 A4 A5 gender #> 61617 2 4 3 4 4 0 #> 61618 2 4 5 2 5 1 #> 61620 5 4 5 4 4 1 #> 61621 4 4 6 5 5 1 #> 61622 2 3 3 4 5 0 #> 61623 6 6 5 6 5 1 vars <- c(\"A1\", \"A2\", \"A3\", \"A4\", \"A5\") items_male <- part_bfi[part_bfi$gender == 0, vars] items_female <- part_bfi[part_bfi$gender == 1, vars] params_male <- estimate_params(data = items_male, n_levels = 6) params_female <- estimate_params(data = items_female, n_levels = 6) set.seed(12345) # Ensure reproducible results new_items_male <- rlikert( size = nrow(items_male), n_items = 5, n_levels = 6, mean = params_male[\"mean\", ], sd = params_male[\"sd\", ], corr = cor(items_male) ) new_items_female <- rlikert( size = nrow(items_female), n_items = 5, n_levels = 6, mean = params_female[\"mean\", ], sd = params_female[\"sd\", ], corr = cor(items_female) ) # Combine new items and gender in new data frame new_data <- data.frame(rbind(new_items_male, new_items_female)) new_data$gender <- c(rep(0, nrow(items_male)), rep(1, nrow(items_female))) head(new_data) #> Y1 Y2 Y3 Y4 Y5 gender #> 1 3 5 5 4 5 0 #> 2 1 5 4 4 4 0 #> 3 2 6 5 6 4 0 #> 4 4 4 4 6 5 0 #> 5 4 5 3 2 2 0 #> 6 5 4 5 6 5 0 # Reverse the first item because it has negative correlations part_bfi$A1 <- (min(part_bfi$A1) + max(part_bfi$A1)) - part_bfi$A1 new_data$Y1 <- (min(new_data$Y1) + max(new_data$Y1)) - new_data$Y1 # Create agreeableness scale scores part_bfi$agreeable <- rowMeans(part_bfi[, vars]) new_data$agreeable <- rowMeans(new_data[, c(\"Y1\", \"Y2\", \"Y3\", \"Y4\", \"Y5\")])"},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Marko Lalovic. Author, maintainer.","code":""},{"path":"https://markolalovic.github.io/latent2likert/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Lalovic M (2024). latent2likert: Converting Latent Variables Likert Scale Responses. R package version 1.2.2, https://latent2likert.lalovic.io/.","code":"@Manual{, title = {latent2likert: Converting Latent Variables into Likert Scale Responses}, author = {Marko Lalovic}, year = {2024}, note = {R package version 1.2.2}, url = {https://latent2likert.lalovic.io/}, }"},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Converting Latent Variables into Likert Scale Responses","text":"latent2likert package designed effectively simulate discretization process inherent Likert scales minimizing distortion. converts continuous latent variables ordinal categories generate Likert scale item responses. particularly useful accurately modeling analyzing survey data use Likert scales, especially applying statistical techniques require metric data.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Converting Latent Variables into Likert Scale Responses","text":"can install released version CRAN: latest development version GitHub:","code":"install.packages(\"latent2likert\") devtools::install_github(\"markolalovic/latent2likert\")"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"dependencies","dir":"","previous_headings":"","what":"Dependencies","title":"Converting Latent Variables into Likert Scale Responses","text":"keep package lightweight, latent2likert imports mvtnorm, along standard R packages stats graphics, typically included R releases. additional suggested dependency package sn, required generating random responses correlated Likert items based multivariate skew normal distribution. package prompts user install dependency interactive sessions needed.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"features","dir":"","previous_headings":"","what":"Features","title":"Converting Latent Variables into Likert Scale Responses","text":"rlikert: Generates random responses Likert scale questions based specified means standard deviations latent variables, optional settings skewness correlations. estimate_params: Estimates latent parameters existing survey data.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"structure","dir":"","previous_headings":"","what":"Structure","title":"Converting Latent Variables into Likert Scale Responses","text":"Overview inputs outputs.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"using-rlikert","dir":"","previous_headings":"","what":"Using rlikert","title":"Converting Latent Variables into Likert Scale Responses","text":"can use rlikert function simulate Likert item responses. generate sample random responses one item 5-point Likert scale, use: generate responses multiple items specified parameters: can also provide correlation matrix: Note correlations among Likert response variables estimates actual correlations latent variables, estimates typically lower:","code":"library(latent2likert) rlikert(size = 10, n_items = 1, n_levels = 5) #> [1] 4 4 2 3 5 2 4 2 3 3 rlikert(size = 10, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = 0.5) #> Y1 Y2 Y3 #> [1,] 3 2 4 #> [2,] 2 1 1 #> [3,] 2 1 2 #> [4,] 3 2 4 #> [5,] 2 2 4 #> [6,] 2 3 5 #> [7,] 3 1 2 #> [8,] 2 2 3 #> [9,] 2 3 5 #> [10,] 3 2 5 corr <- matrix(c(1.00, -0.63, -0.39, -0.63, 1.00, 0.41, -0.39, 0.41, 1.00), nrow=3) data <- rlikert(size = 10^3, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = corr) cor(data) #> Y1 Y2 Y3 #> Y1 1.0000000 -0.5223151 -0.3449648 #> Y2 -0.5223151 1.0000000 0.3398699 #> Y3 -0.3449648 0.3398699 1.0000000"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"using-estimate_params","dir":"","previous_headings":"","what":"Using estimate_params","title":"Converting Latent Variables into Likert Scale Responses","text":"Given data, can estimate values latent parameters using:","code":"estimate_params(data, n_levels = c(4, 5, 6), skew = 0) #> items #> estimates Y1 Y2 Y3 #> mean 0.006261483 -0.952847125 -0.011843866 #> sd 0.745185144 1.012219189 0.954714824"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"transformation","dir":"","previous_headings":"","what":"Transformation","title":"Converting Latent Variables into Likert Scale Responses","text":"visualize transformation, can use plot_likert_transform(). plots densities latent variables first row transformed discrete probability distributions : Transformation latent variables Likert response variables. Note , depending value skewness parameter, normal latent distribution used skew = 0, otherwise skew normal distribution used. value skewness restricted range -0.95 0.95, skew >= -0.95 skew <= 0.95.","code":"plot_likert_transform(n_items = 3, n_levels = 5, mean = c(0, -1, 0), sd = c(0.8, 1, 1), skew = c(0, 0, 0.5))"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"further-reading","dir":"","previous_headings":"","what":"Further Reading","title":"Converting Latent Variables into Likert Scale Responses","text":"detailed information practical examples, please refer package vignette. implemented algorithms described functions reference.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"related-r-packages","dir":"","previous_headings":"","what":"Related R Packages","title":"Converting Latent Variables into Likert Scale Responses","text":"Alternatively, can simulate Likert item responses using draw_likert function fabricatr package. function recodes latent variable Likert response variable specifying intervals subdivide continuous range. latent2likert package, however, offers advantage automatically calculating optimal intervals minimize distortion latent variable Likert response variable normal skew normal latent distributions, eliminating need manually specify intervals. also several alternative approaches rely latent distributions. One method involves directly defining discrete probability distribution sampling using sample function R likert function wakefield package. Another approach specify means, standard deviations, correlations among Likert response variables. , can use LikertMakeR SimCorMultRes generate correlated multinomial responses. Additionally, can define data generating process. familiar item response theory, mirt package allows users specify discrimination difficulty parameters response category.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":null,"dir":"Reference","previous_headings":"","what":"Discretize Density — discretize_density","title":"Discretize Density — discretize_density","text":"Transforms density function continuous random variable discrete probability distribution minimal distortion using Lloyd-Max algorithm.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Discretize Density — discretize_density","text":"","code":"discretize_density(density_fn, n_levels, eps = 1e-06)"},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Discretize Density — discretize_density","text":"density_fn probability density function. n_levels cardinality set possible outcomes. eps convergence threshold algorithm.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Discretize Density — discretize_density","text":"list containing: prob discrete probability distribution. endp endpoints intervals partition continuous domain. repr representation points intervals. dist distortion measured mean-squared error (MSE).","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Discretize Density — discretize_density","text":"function addresses problem transforming continuous random variable \\(X\\) discrete random variable \\(Y\\) minimal distortion. Distortion measured mean-squared error (MSE): $$ \\text{E}\\left[ (X - Y)^2 \\right] = \\sum_{k=1}^{K} \\int_{x_{k-1}}^{x_{k}} f_{X}(x) \\left( x - r_{k} \\right)^2 \\, dx $$ : \\(f_{X}\\) probability density function \\(X\\), \\(K\\) number possible outcomes \\(Y\\), \\(x_{k}\\) endpoints intervals partition domain \\(X\\), \\(r_{k}\\) representation points intervals. problem solved using following iterative procedure: \\(1.\\) Start arbitrary initial set representation points: \\(r_{1} < r_{2} < \\dots < r_{K}\\). \\(2.\\) Repeat following steps improvement MSE falls given \\(\\varepsilon\\). \\(3.\\) Calculate endpoints \\(x_{k} = (r_{k+1} + r_{k})/2\\) \\(k = 1, \\dots, K-1\\) set \\(x_{0}\\) \\(x_{K}\\) \\(-\\infty\\) \\(\\infty\\), respectively. \\(4.\\) Update representation points setting \\(r_{k}\\) equal conditional mean \\(X\\) given \\(X \\(x_{k-1}, x_{k})\\) \\(k = 1, \\dots, K\\). execution step \\((3)\\) step \\((4)\\), MSE decreases remains . MSE nonnegative, approaches limit. algorithm terminates improvement MSE less given \\(\\varepsilon > 0\\), ensuring convergence finite number iterations. procedure known Lloyd-Max's algorithm, initially used scalar quantization closely related k-means algorithm. Local convergence proven log-concave density functions Kieffer. Many common probability distributions log-concave including normal skew normal distribution, shown Azzalini.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Discretize Density — discretize_density","text":"Azzalini, . (1985). class distributions includes normal ones. Scandinavian Journal Statistics 12(2), 171–178. Kieffer, J. (1983). Uniqueness locally optimal quantizer log-concave density convex error function. IEEE Transactions Information Theory 29, 42–47. Lloyd, S. (1982). Least squares quantization PCM. IEEE Transactions Information Theory 28 (2), 129–137.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Discretize Density — discretize_density","text":"","code":"discretize_density(density_fn = stats::dnorm, n_levels = 5) #> $prob #> [1] 0.1063142 0.2444957 0.2983803 0.2444957 0.1063142 #> #> $endp #> [1] -Inf -1.2463707 -0.3831349 0.3831349 1.2463707 Inf #> #> $repr #> [1] -1.7264716 -0.7662698 0.0000000 0.7662698 1.7264716 #> #> $dist #> [1] 0.07994185 #> discretize_density(density_fn = function(x) { 2 * stats::dnorm(x) * stats::pnorm(0.5 * x) }, n_levels = 4) #> $prob #> [1] 0.1647781 0.3380772 0.3359810 0.1611637 #> #> $endp #> [1] -Inf -0.5537368 0.3597728 1.2808536 Inf #> #> $repr #> [1] -1.04423728 -0.06323628 0.78278182 1.77892538 #> #> $dist #> [1] 0.1026681 #>"},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate mean and standard deviation — estimate_mean_and_sd","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"Estimates mean standard deviation latent variable given discrete probabilities observed Likert scale responses.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"","code":"estimate_mean_and_sd(prob, n_levels, skew = 0, eps = 1e-06, maxit = 100)"},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"prob vector probabilities response category. n_levels number response categories Likert scale item. skew marginal skewness latent variable, defaults 0. eps tolerance convergence, defaults 1e-6. maxit maximum number iterations, defaults 100.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"numeric vector two elements: estimated mean standard deviation.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"function uses iterative algorithm solve system non-linear equations describe relationship continuous latent variable observed discrete probability distribution Likert scale responses. algorithm ensures stability reparameterizing system applying constraints prevent stepping invalid regions.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate Latent Parameters — estimate_params","title":"Estimate Latent Parameters — estimate_params","text":"Estimates location scaling parameters latent variables existing survey data.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate Latent Parameters — estimate_params","text":"","code":"estimate_params(data, n_levels, skew = 0)"},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate Latent Parameters — estimate_params","text":"data survey data columns representing individual items. Apart , data can almost class \"data.frame\" \"matrix\" \"array\". n_levels number response categories, vector number. skew marginal skewness latent variables, defaults 0.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate Latent Parameters — estimate_params","text":"table estimated parameters latent variable.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Estimate Latent Parameters — estimate_params","text":"relationship continuous random variable \\(X\\) discrete probability distribution \\(p_k\\), \\(k = 1, \\dots, K\\), can described system non-linear equations: $$ p_{k} = F_{X}\\left( \\frac{x_{k - 1} - \\xi}{\\omega} \\right) - F_{X}\\left( \\frac{x_{k} - \\xi}{\\omega} \\right) \\quad \\text{} \\ k = 1, \\dots, K $$ : \\(F_{X}\\) cumulative distribution function \\(X\\), \\(K\\) number possible response categories, \\(x_{k}\\) endpoints defining boundaries response categories, \\(p_{k}\\) probability \\(k\\)-th response category, \\(\\xi\\) location parameter \\(X\\), \\(\\omega\\) scaling parameter \\(X\\). endpoints \\(x_{k}\\) calculated discretizing random variable \\(Z\\) mean 0 standard deviation 1 follows distribution \\(X\\). solving system non-linear equations iteratively, can find parameters best fit observed discrete probability distribution \\(p_{k}\\). function estimate_params: Computes proportion table responses item. Estimates probabilities \\(p_{k}\\) item. Computes estimates \\(\\xi\\) \\(\\omega\\) item. Combines estimated parameters items table.","code":""},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Estimate Latent Parameters — estimate_params","text":"","code":"data(part_bfi) vars <- c(\"A1\", \"A2\", \"A3\", \"A4\", \"A5\") estimate_params(data = part_bfi[, vars], n_levels = 6) #> items #> estimates A1 A2 A3 A4 A5 #> mean -0.9759824 1.0830781 0.9776057 1.1723519 0.9006478 #> sd 1.1798137 0.7968668 0.8432599 1.3825407 0.8648150"},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":null,"dir":"Reference","previous_headings":"","what":"Agreeableness and Gender Data — part_bfi","title":"Agreeableness and Gender Data — part_bfi","text":"dataset cleaned version small part bfi dataset psychTools package. contains responses first 5 items agreeableness scale International Personality Item Pool (IPIP) gender attribute. includes responses 2800 subjects. item answered six point Likert scale ranging 1 (inaccurate), 6 (accurate). Gender coded 0 male 1 female. Missing values addressed using mode imputation.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Agreeableness and Gender Data — part_bfi","text":"","code":"data(part_bfi)"},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Agreeableness and Gender Data — part_bfi","text":"object class \"data.frame\" 2800 observations following 6 variables: A1 indifferent feelings others. A2 Inquire others' well-. A3 Know comfort others. A4 Love children. A5 Make people feel ease. gender Gender respondent.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Agreeableness and Gender Data — part_bfi","text":"International Personality Item Pool (https://ipip.ori.org) https://search.r-project.org/CRAN/refmans/psychTools/html/bfi.html","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Agreeableness and Gender Data — part_bfi","text":"Revelle, W. (2024). Psych: Procedures Psychological, Psychometric, Personality Research. Evanston, Illinois: Northwestern University. https://CRAN.R-project.org/package=psych","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Agreeableness and Gender Data — part_bfi","text":"","code":"data(part_bfi) head(part_bfi) #> A1 A2 A3 A4 A5 gender #> 61617 2 4 3 4 4 0 #> 61618 2 4 5 2 5 1 #> 61620 5 4 5 4 4 1 #> 61621 4 4 6 5 5 1 #> 61622 2 3 3 4 5 0 #> 61623 6 6 5 6 5 1"},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot Transformation — plot_likert_transform","title":"Plot Transformation — plot_likert_transform","text":"Plots densities latent variables corresponding transformed discrete probability distributions.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot Transformation — plot_likert_transform","text":"","code":"plot_likert_transform(n_items, n_levels, mean = 0, sd = 1, skew = 0)"},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot Transformation — plot_likert_transform","text":"n_items number Likert scale items (questions). n_levels number response categories Likert item. Integer vector integers. mean means latent variables. Numeric vector numerics. Defaults 0. sd standard deviations latent variables. Numeric vector numerics. Defaults 1. skew marginal skewness latent variables. Numeric vector numerics. Defaults 0.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot Transformation — plot_likert_transform","text":"NULL. function produces plot.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot Transformation — plot_likert_transform","text":"","code":"plot_likert_transform(n_items = 3, n_levels = c(3, 4, 5)) plot_likert_transform(n_items = 3, n_levels = 5, mean = c(0, 1, 2)) plot_likert_transform(n_items = 3, n_levels = 5, sd = c(0.8, 1, 1.2)) plot_likert_transform(n_items = 3, n_levels = 5, skew = c(-0.5, 0, 0.5))"},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculate Response Proportions — response_prop","title":"Calculate Response Proportions — response_prop","text":"Returns table proportions possible response category.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculate Response Proportions — response_prop","text":"","code":"response_prop(data, n_levels)"},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculate Response Proportions — response_prop","text":"data numeric vector matrix responses. n_levels number response categories.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculate Response Proportions — response_prop","text":"table response category proportions.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Calculate Response Proportions — response_prop","text":"","code":"data <- c(1, 2, 2, 3, 3, 3) response_prop(data, n_levels = 3) #> 1 2 3 #> 0.1666667 0.3333333 0.5000000 data_matrix <- matrix(c(1, 2, 2, 3, 3, 3), ncol = 2) response_prop(data_matrix, n_levels = 3) #> Response #> Item 1 2 3 #> [1,] 0.3333333 0.6666667 0 #> [2,] 0.0000000 0.0000000 1"},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate Random Responses — rlikert","title":"Generate Random Responses — rlikert","text":"Generates array random responses Likert-type questions based specified latent variables.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate Random Responses — rlikert","text":"","code":"rlikert(size, n_items, n_levels, mean = 0, sd = 1, skew = 0, corr = 0)"},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate Random Responses — rlikert","text":"size number observations. n_items number Likert scale items (number questions). n_levels number response categories item. Integer vector integers. mean means latent variables. Numeric vector numerics. Defaults 0. sd standard deviations latent variables. Numeric vector numerics. Defaults 1. skew marginal skewness latent variables. Numeric vector numerics. Defaults 0. corr correlations latent variables. Can single numeric value representing correlation pairs, actual correlation matrix. Defaults 0.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate Random Responses — rlikert","text":"matrix random responses dimensions size n_items. column names Y1, Y2, ..., Yn n number items. entry matrix represents Likert scale response, ranging 1 n_levels.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Generate Random Responses — rlikert","text":"","code":"# Generate responses for a single item with 5 levels rlikert(size = 10, n_items = 1, n_levels = 5) #> [1] 3 5 4 3 3 2 2 3 4 4 # Generate responses for three items with different levels and parameters rlikert( size = 10, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = 0.5 ) #> Y1 Y2 Y3 #> [1,] 3 1 3 #> [2,] 2 1 3 #> [3,] 3 4 2 #> [4,] 2 1 2 #> [5,] 2 2 2 #> [6,] 3 2 2 #> [7,] 3 4 4 #> [8,] 2 1 2 #> [9,] 2 2 4 #> [10,] 3 4 4 # Generate responses with a correlation matrix corr <- matrix(c( 1.00, -0.63, -0.39, -0.63, 1.00, 0.41, -0.39, 0.41, 1.00 ), nrow = 3) data <- rlikert( size = 1000, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = corr )"},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":null,"dir":"Reference","previous_headings":"","what":"Simulate Likert Scale Item Responses — simulate_likert","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"Simulates Likert scale item responses based specified number response categories centered parameters latent variable.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"","code":"simulate_likert(n_levels, cp)"},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"n_levels number response categories Likert scale item. cp centered parameters latent variable. Named vector including mean (mu), standard deviation (sd), skewness (skew). Skewness must -0.95 0.95.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"named vector probabilities response category.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"simulation process uses following model detailed Boari Nai-Ruscone. Let \\(X\\) continuous variable interest, measured using Likert scale questions \\(K\\) response categories. observed discrete variable \\(Y\\) defined follows: $$ Y = k, \\quad \\text{ } \\ \\ x_{k - 1} < X \\leq x_{k} \\quad \\text{ } \\ \\ k = 1, \\dots, K $$ \\(x_{k}\\), \\(k = 0, \\dots, K\\) endpoints defined domain \\(X\\) : $$ -\\infty = x_{0} < x_{1} < \\dots < x_{K - 1} < x_{K} = \\infty. $$ endpoints dictate transformation density \\(f_{X}\\) \\(X\\) discrete probability distribution: $$ \\text{Pr}(Y = k) = \\int_{x_{k - 1}}^{x_{k}} f_{X}(x) \\, dx \\quad \\text{ } \\ \\ k = 1, \\dots, K. $$ continuous latent variable modeled using skew normal distribution. function simulate_likert performs following steps: Ensures centered parameters within acceptable range. Converts centered parameters direct parameters. Defines density function skew normal distribution. Computes probabilities response category using optimal endpoints.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"Boari, G. Nai Ruscone, M. (2015). procedure simulating Likert scale item responses. Electronic Journal Applied Statistical Analysis 8(3), 288–297. doi:10.1285/i20705948v8n3p288","code":""},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"","code":"cp <- c(mu = 0, sd = 1, skew = 0.5) simulate_likert(n_levels = 5, cp = cp) #> 1 2 3 4 5 #> 0.15995244 0.29511214 0.28435807 0.18964493 0.07093241 cp2 <- c(mu = 1, sd = 2, skew = -0.3) simulate_likert(n_levels = 7, cp = cp2) #> 1 2 3 4 5 6 7 #> 0.08311645 0.07169556 0.07928979 0.08940184 0.10477572 0.13413804 0.43758260"},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-010","dir":"Changelog","previous_headings":"","what":"Version 0.1.0","title":"Version 0.1.0","text":"Release date: 2020-10-17 Initial release (development version). Tested platforms: x86_64-pc-linux-gnu (64-bit) x86_64-w64-mingw32 (64-bit).","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-100","dir":"Changelog","previous_headings":"","what":"Version 1.0.0","title":"Version 1.0.0","text":"Release date: 2024-03-28 Added option generate correlated Likert scale items rlikert() function. Added estimate_params() function estimating parameters existing survey data. Resolved dependency issues. Reduced dependency standard R packages: mvtnorm, stats, graphics. sn package now required generating correlated responses using skew normal distribution. Added user prompts install sn package needed.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-110","dir":"Changelog","previous_headings":"","what":"Version 1.1.0","title":"Version 1.1.0","text":"Release date: 2024-06-06 Minor updates functions vignettes.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-111","dir":"Changelog","previous_headings":"","what":"Version 1.1.1","title":"Version 1.1.1","text":"Release date: 2024-06-06 Renamed package responsesR latent2likert better reflect purpose converting latent variables Likert scale responses. Improved package website documentation. Note: codebase development, finer details may change.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-121","dir":"Changelog","previous_headings":"","what":"Version 1.2.1","title":"Version 1.2.1","text":"CRAN release: 2024-06-24 Release date: 2024-06-12 Refactored code enhanced modularity maintainability. Modularized core functions improved readability. Improved structure organization codebase. Enhanced error handling various correlation input scenarios.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-122","dir":"Changelog","previous_headings":"","what":"Version 1.2.2","title":"Version 1.2.2","text":"Release date: 2024-07-26 Exported previously internal function estimate_mean_and_sd based user feedback, now available direct use. Moved package sn Suggests. Fixed vignette building errors.","code":""}] +[{"path":"https://markolalovic.github.io/latent2likert/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 Marko Lalovic Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Using latent2likert","text":"social sciences, variables interest often conceptualized latent variables — hidden continuous variables measured Likert scale questions, typically categorized Strongly disagree, Disagree, Neutral, Agree, Strongly agree. Researchers frequently aim uncover latent variables using various statistical techniques. Accurate modeling survey data essential comparative analysis simulation. latent2likert package addresses need providing effective algorithm simulate Likert response variables hypothetical latent variables. vignette provides two practical workflow examples demonstrating use latent2likert package.","code":""},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"simulating-survey-data","dir":"Articles","previous_headings":"","what":"Simulating Survey Data","title":"Using latent2likert","text":"following hypothetical survey simulation loosely based actual comparative study teaching learning R pair introductory statistics labs (McNamara 2024). Imagine situation 10 participants Course 20 participants Course B completed survey. Suppose initial question : “rate experience course?” four possible answers: Poor, Fair, Good, Excellent. Let’s assume participants Course neutral regarding question, participants Course B positive experience average. choosing appropriate parameters latent distributions setting number categories n_levels = 4, can generate hypothetical responses (standard deviation sd = 1 skewness skew = 0, default): summarize results, create data frame responses: results can visualized using grouped bar chart:","code":"library(latent2likert) # Load the package set.seed(12345) # Ensure reproducible results # Generate responses for Course A and Course B responses_A <- rlikert(size = 10, n_items = 1, n_levels = 4, mean = 0, sd = 1) responses_B <- rlikert(size = 20, n_items = 1, n_levels = 4, mean = 1, sd = 1) n_levels <- 4 n_groups <- 2 categories <- c(\"Poor\", \"Fair\", \"Good\", \"Excellent\") # Create a data frame to summarize the responses response_data <- data.frame( Course = rep(c(\"A\", \"B\"), each = n_levels), Response = factor(rep(categories, n_groups), levels = categories), Proportion = c( response_prop(responses_A, n_levels), response_prop(responses_B, n_levels) ) ) # Filter out rows with zero proportions response_data <- response_data[response_data$Proportion > 0, ] response_data #> Course Response Proportion #> 1 A Poor 0.30 #> 2 A Fair 0.20 #> 3 A Good 0.20 #> 4 A Excellent 0.30 #> 6 B Fair 0.10 #> 7 B Good 0.25 #> 8 B Excellent 0.65"},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"pre-and-post-comparison","dir":"Articles","previous_headings":"","what":"Pre and Post Comparison","title":"Using latent2likert","text":"Now suppose survey also asked participants rate skills 5-point Likert scale, ranging 1 (poor) 5 (good) : Programming, Searching Online, Solving Problems. survey completed participants taking course pre post-comparison. Suppose participants’ assessments : Programming skills average increased, Searching Online stayed , Solving Problems increased Course , decreased participants Course B. Let’s simulate survey data scenario: Create data frame responses summarize results: visualize results stacked bar chart:","code":"# Pre- and post-assessments of skills for Course A pre_A <- rlikert(size = 10, n_items = 3, n_levels = 5, mean = c(-1, 0, 1)) post_A <- rlikert(size = 10, n_items = 3, n_levels = 5, mean = c(0, 0, 2)) # Pre- and post-assessments of skills for Course B pre_B <- rlikert(size = 20, n_items = 3, n_levels = 5, mean = c(-1, 0, 1)) post_B <- rlikert(size = 20, n_items = 3, n_levels = 5, mean = c(0, 0, 0)) # Combine pre and post responses into a list pre_post <- list(pre_A, post_A, pre_B, post_B) # Number of items and response levels n_items <- 3 n_levels <- 5 # Define skills assessed skills <- c(\"Programming\", \"Searching online\", \"Solving problems\") # Generate repeated skill labels for questions questions <- rep(rep(skills, each = n_levels), 4) questions <- factor(questions, levels = skills) # Create a data frame to summarize the responses response_data <- data.frame( Course = rep(c(\"Course A\", \"Course B\"), each = 2 * n_items * n_levels), Question = questions, Time = as.factor(rep(c( rep(\"before\", n_items * n_levels), rep(\"after\", n_items * n_levels) ), 2)), Response = rep(seq_len(n_levels), 2 * n_items * 2), Proportion = as.vector(sapply(pre_post, function(d) { as.vector(t(response_prop(d, n_levels))) })) ) head(response_data) #> Course Question Time Response Proportion #> 1 Course A Programming before 1 0.5 #> 2 Course A Programming before 2 0.2 #> 3 Course A Programming before 3 0.3 #> 4 Course A Programming before 4 0.0 #> 5 Course A Programming before 5 0.0 #> 6 Course A Searching online before 1 0.1"},{"path":"https://markolalovic.github.io/latent2likert/articles/using_latent2likert.html","id":"recreating-scale-scores","dir":"Articles","previous_headings":"","what":"Recreating Scale Scores","title":"Using latent2likert","text":"use part bfi data set (Revelle 2024). Specifically, ’ll focus first 5 items corresponding agreeableness. investigate differences agreeableness men women, ’ll also use gender attribute. Load data: Separate items two groups according gender: Estimate parameters latent variables, assuming normal providing number possible response categories n_levels = 6: Generate new responses items using estimated parameters estimated correlations: Create agreeableness scale scores groups participants taking average 5 items: results can visualized grouped boxplot:","code":"data(part_bfi) head(part_bfi) #> A1 A2 A3 A4 A5 gender #> 61617 2 4 3 4 4 0 #> 61618 2 4 5 2 5 1 #> 61620 5 4 5 4 4 1 #> 61621 4 4 6 5 5 1 #> 61622 2 3 3 4 5 0 #> 61623 6 6 5 6 5 1 vars <- c(\"A1\", \"A2\", \"A3\", \"A4\", \"A5\") items_male <- part_bfi[part_bfi$gender == 0, vars] items_female <- part_bfi[part_bfi$gender == 1, vars] params_male <- estimate_params(data = items_male, n_levels = 6) params_female <- estimate_params(data = items_female, n_levels = 6) set.seed(12345) # Ensure reproducible results new_items_male <- rlikert( size = nrow(items_male), n_items = 5, n_levels = 6, mean = params_male[\"mean\", ], sd = params_male[\"sd\", ], corr = cor(items_male) ) new_items_female <- rlikert( size = nrow(items_female), n_items = 5, n_levels = 6, mean = params_female[\"mean\", ], sd = params_female[\"sd\", ], corr = cor(items_female) ) # Combine new items and gender in new data frame new_data <- data.frame(rbind(new_items_male, new_items_female)) new_data$gender <- c(rep(0, nrow(items_male)), rep(1, nrow(items_female))) head(new_data) #> Y1 Y2 Y3 Y4 Y5 gender #> 1 3 5 5 4 5 0 #> 2 1 5 4 4 4 0 #> 3 2 6 5 6 4 0 #> 4 4 4 4 6 5 0 #> 5 4 5 3 2 2 0 #> 6 5 4 5 6 5 0 # Reverse the first item because it has negative correlations part_bfi$A1 <- (min(part_bfi$A1) + max(part_bfi$A1)) - part_bfi$A1 new_data$Y1 <- (min(new_data$Y1) + max(new_data$Y1)) - new_data$Y1 # Create agreeableness scale scores part_bfi$agreeable <- rowMeans(part_bfi[, vars]) new_data$agreeable <- rowMeans(new_data[, c(\"Y1\", \"Y2\", \"Y3\", \"Y4\", \"Y5\")])"},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Marko Lalovic. Author, maintainer.","code":""},{"path":"https://markolalovic.github.io/latent2likert/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Lalovic M (2024). latent2likert: Converting Latent Variables Likert Scale Responses. R package version 1.2.2, https://latent2likert.lalovic.io/.","code":"@Manual{, title = {latent2likert: Converting Latent Variables into Likert Scale Responses}, author = {Marko Lalovic}, year = {2024}, note = {R package version 1.2.2}, url = {https://latent2likert.lalovic.io/}, }"},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Converting Latent Variables into Likert Scale Responses","text":"latent2likert package designed effectively simulate discretization process inherent Likert scales minimizing distortion. converts continuous latent variables ordinal categories generate Likert scale item responses. particularly useful accurately modeling analyzing survey data use Likert scales, especially applying statistical techniques require metric data.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Converting Latent Variables into Likert Scale Responses","text":"can install released version CRAN: latest development version GitHub:","code":"install.packages(\"latent2likert\") devtools::install_github(\"markolalovic/latent2likert\")"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"dependencies","dir":"","previous_headings":"","what":"Dependencies","title":"Converting Latent Variables into Likert Scale Responses","text":"keep package lightweight, latent2likert imports mvtnorm, along standard R packages stats graphics, typically included R releases. additional suggested dependency package sn, required generating random responses correlated Likert items based multivariate skew normal distribution. package prompts user install dependency interactive sessions needed.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"features","dir":"","previous_headings":"","what":"Features","title":"Converting Latent Variables into Likert Scale Responses","text":"rlikert: Generates random responses Likert scale questions based specified means standard deviations latent variables, optional settings skewness correlations. estimate_params: Estimates latent parameters existing survey data.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"structure","dir":"","previous_headings":"","what":"Structure","title":"Converting Latent Variables into Likert Scale Responses","text":"Overview inputs outputs.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"using-rlikert","dir":"","previous_headings":"","what":"Using rlikert","title":"Converting Latent Variables into Likert Scale Responses","text":"can use rlikert function simulate Likert item responses. generate sample random responses one item 5-point Likert scale, use: generate responses multiple items specified parameters: can also provide correlation matrix: Note correlations among Likert response variables estimates actual correlations latent variables, estimates typically lower:","code":"library(latent2likert) rlikert(size = 10, n_items = 1, n_levels = 5) #> [1] 4 4 2 3 5 2 4 2 3 3 rlikert(size = 10, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = 0.5) #> Y1 Y2 Y3 #> [1,] 3 2 4 #> [2,] 2 1 1 #> [3,] 2 1 2 #> [4,] 3 2 4 #> [5,] 2 2 4 #> [6,] 2 3 5 #> [7,] 3 1 2 #> [8,] 2 2 3 #> [9,] 2 3 5 #> [10,] 3 2 5 corr <- matrix(c(1.00, -0.63, -0.39, -0.63, 1.00, 0.41, -0.39, 0.41, 1.00), nrow=3) data <- rlikert(size = 10^3, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = corr) cor(data) #> Y1 Y2 Y3 #> Y1 1.0000000 -0.5223151 -0.3449648 #> Y2 -0.5223151 1.0000000 0.3398699 #> Y3 -0.3449648 0.3398699 1.0000000"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"using-estimate_params","dir":"","previous_headings":"","what":"Using estimate_params","title":"Converting Latent Variables into Likert Scale Responses","text":"Given data, can estimate values latent parameters using:","code":"estimate_params(data, n_levels = c(4, 5, 6), skew = 0) #> items #> estimates Y1 Y2 Y3 #> mean 0.006261483 -0.952847125 -0.011843866 #> sd 0.745185144 1.012219189 0.954714824"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"transformation","dir":"","previous_headings":"","what":"Transformation","title":"Converting Latent Variables into Likert Scale Responses","text":"visualize transformation, can use plot_likert_transform(). plots densities latent variables first row transformed discrete probability distributions : Transformation latent variables Likert response variables. Note , depending value skewness parameter, normal latent distribution used skew = 0, otherwise skew normal distribution used. value skewness restricted range -0.95 0.95, skew >= -0.95 skew <= 0.95.","code":"plot_likert_transform(n_items = 3, n_levels = 5, mean = c(0, -1, 0), sd = c(0.8, 1, 1), skew = c(0, 0, 0.5))"},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"further-reading","dir":"","previous_headings":"","what":"Further Reading","title":"Converting Latent Variables into Likert Scale Responses","text":"detailed information practical examples, please refer package vignette. implemented algorithms described functions reference.","code":""},{"path":"https://markolalovic.github.io/latent2likert/index.html","id":"related-r-packages","dir":"","previous_headings":"","what":"Related R Packages","title":"Converting Latent Variables into Likert Scale Responses","text":"Alternatively, can simulate Likert item responses using draw_likert function fabricatr package. function recodes latent variable Likert response variable specifying intervals subdivide continuous range. latent2likert package, however, offers advantage automatically calculating optimal intervals minimize distortion latent variable Likert response variable normal skew normal latent distributions, eliminating need manually specify intervals. also several alternative approaches rely latent distributions. One method involves directly defining discrete probability distribution sampling using sample function R likert function wakefield package. Another approach specify means, standard deviations, correlations among Likert response variables. , can use LikertMakeR SimCorMultRes generate correlated multinomial responses. Additionally, can define data generating process. familiar item response theory, mirt package allows users specify discrimination difficulty parameters response category.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":null,"dir":"Reference","previous_headings":"","what":"Discretize Density — discretize_density","title":"Discretize Density — discretize_density","text":"Transforms density function continuous random variable discrete probability distribution minimal distortion using Lloyd-Max algorithm.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Discretize Density — discretize_density","text":"","code":"discretize_density(density_fn, n_levels, eps = 1e-06)"},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Discretize Density — discretize_density","text":"density_fn probability density function. n_levels cardinality set possible outcomes. eps convergence threshold algorithm.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Discretize Density — discretize_density","text":"list containing: prob discrete probability distribution. endp endpoints intervals partition continuous domain. repr representation points intervals. dist distortion measured mean-squared error (MSE).","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Discretize Density — discretize_density","text":"function addresses problem transforming continuous random variable \\(X\\) discrete random variable \\(Y\\) minimal distortion. Distortion measured mean-squared error (MSE): $$ \\text{E}\\left[ (X - Y)^2 \\right] = \\sum_{k=1}^{K} \\int_{x_{k-1}}^{x_{k}} f_{X}(x) \\left( x - r_{k} \\right)^2 \\, dx $$ : \\(f_{X}\\) probability density function \\(X\\), \\(K\\) number possible outcomes \\(Y\\), \\(x_{k}\\) endpoints intervals partition domain \\(X\\), \\(r_{k}\\) representation points intervals. problem solved using following iterative procedure: \\(1.\\) Start arbitrary initial set representation points: \\(r_{1} < r_{2} < \\dots < r_{K}\\). \\(2.\\) Repeat following steps improvement MSE falls given \\(\\varepsilon\\). \\(3.\\) Calculate endpoints \\(x_{k} = (r_{k+1} + r_{k})/2\\) \\(k = 1, \\dots, K-1\\) set \\(x_{0}\\) \\(x_{K}\\) \\(-\\infty\\) \\(\\infty\\), respectively. \\(4.\\) Update representation points setting \\(r_{k}\\) equal conditional mean \\(X\\) given \\(X \\(x_{k-1}, x_{k})\\) \\(k = 1, \\dots, K\\). execution step \\((3)\\) step \\((4)\\), MSE decreases remains . MSE nonnegative, approaches limit. algorithm terminates improvement MSE less given \\(\\varepsilon > 0\\), ensuring convergence finite number iterations. procedure known Lloyd-Max's algorithm, initially used scalar quantization closely related k-means algorithm. Local convergence proven log-concave density functions Kieffer. Many common probability distributions log-concave including normal skew normal distribution, shown Azzalini.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Discretize Density — discretize_density","text":"Azzalini, . (1985). class distributions includes normal ones. Scandinavian Journal Statistics 12(2), 171–178. Kieffer, J. (1983). Uniqueness locally optimal quantizer log-concave density convex error function. IEEE Transactions Information Theory 29, 42–47. Lloyd, S. (1982). Least squares quantization PCM. IEEE Transactions Information Theory 28 (2), 129–137.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/discretize_density.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Discretize Density — discretize_density","text":"","code":"discretize_density(density_fn = stats::dnorm, n_levels = 5) #> $prob #> [1] 0.1063142 0.2444957 0.2983803 0.2444957 0.1063142 #> #> $endp #> [1] -Inf -1.2463707 -0.3831349 0.3831349 1.2463707 Inf #> #> $repr #> [1] -1.7264716 -0.7662698 0.0000000 0.7662698 1.7264716 #> #> $dist #> [1] 0.07994185 #> discretize_density(density_fn = function(x) { 2 * stats::dnorm(x) * stats::pnorm(0.5 * x) }, n_levels = 4) #> $prob #> [1] 0.1647781 0.3380772 0.3359810 0.1611637 #> #> $endp #> [1] -Inf -0.5537368 0.3597728 1.2808536 Inf #> #> $repr #> [1] -1.04423728 -0.06323628 0.78278182 1.77892538 #> #> $dist #> [1] 0.1026681 #>"},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate mean and standard deviation — estimate_mean_and_sd","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"Estimates mean standard deviation latent variable given discrete probabilities observed Likert scale responses.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"","code":"estimate_mean_and_sd(prob, n_levels, skew = 0, eps = 1e-06, maxit = 100)"},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"prob named vector probabilities response category. n_levels number response categories Likert scale item. skew marginal skewness latent variable, defaults 0. eps tolerance convergence, defaults 1e-6. maxit maximum number iterations, defaults 100.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"numeric vector two elements: estimated mean standard deviation.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"function uses iterative algorithm solve system non-linear equations describe relationship continuous latent variable observed discrete probability distribution Likert scale responses. algorithm ensures stability reparameterizing system applying constraints prevent stepping invalid regions.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_mean_and_sd.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Estimate mean and standard deviation — estimate_mean_and_sd","text":"","code":"prob <- c(\"1\" = 0.313, \"2\" = 0.579, \"3\" = 0.105, \"4\" = 0.003) # returns estimates that are close to the actual mean and sd: c(-1, 0.5) estimate_mean_and_sd(prob, 5) #> [1] -1.0025695 0.5004155"},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate Latent Parameters — estimate_params","title":"Estimate Latent Parameters — estimate_params","text":"Estimates location scaling parameters latent variables existing survey data.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate Latent Parameters — estimate_params","text":"","code":"estimate_params(data, n_levels, skew = 0)"},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate Latent Parameters — estimate_params","text":"data survey data columns representing individual items. Apart , data can almost class \"data.frame\" \"matrix\" \"array\". n_levels number response categories, vector number. skew marginal skewness latent variables, defaults 0.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate Latent Parameters — estimate_params","text":"table estimated parameters latent variable.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Estimate Latent Parameters — estimate_params","text":"relationship continuous random variable \\(X\\) discrete probability distribution \\(p_k\\), \\(k = 1, \\dots, K\\), can described system non-linear equations: $$ p_{k} = F_{X}\\left( \\frac{x_{k - 1} - \\xi}{\\omega} \\right) - F_{X}\\left( \\frac{x_{k} - \\xi}{\\omega} \\right) \\quad \\text{} \\ k = 1, \\dots, K $$ : \\(F_{X}\\) cumulative distribution function \\(X\\), \\(K\\) number possible response categories, \\(x_{k}\\) endpoints defining boundaries response categories, \\(p_{k}\\) probability \\(k\\)-th response category, \\(\\xi\\) location parameter \\(X\\), \\(\\omega\\) scaling parameter \\(X\\). endpoints \\(x_{k}\\) calculated discretizing random variable \\(Z\\) mean 0 standard deviation 1 follows distribution \\(X\\). solving system non-linear equations iteratively, can find parameters best fit observed discrete probability distribution \\(p_{k}\\). function estimate_params: Computes proportion table responses item. Estimates probabilities \\(p_{k}\\) item. Computes estimates \\(\\xi\\) \\(\\omega\\) item. Combines estimated parameters items table.","code":""},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/reference/estimate_params.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Estimate Latent Parameters — estimate_params","text":"","code":"data(part_bfi) vars <- c(\"A1\", \"A2\", \"A3\", \"A4\", \"A5\") estimate_params(data = part_bfi[, vars], n_levels = 6) #> items #> estimates A1 A2 A3 A4 A5 #> mean -0.9759824 1.0830781 0.9776057 1.1723519 0.9006478 #> sd 1.1798137 0.7968668 0.8432599 1.3825407 0.8648150"},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":null,"dir":"Reference","previous_headings":"","what":"Agreeableness and Gender Data — part_bfi","title":"Agreeableness and Gender Data — part_bfi","text":"dataset cleaned version small part bfi dataset psychTools package. contains responses first 5 items agreeableness scale International Personality Item Pool (IPIP) gender attribute. includes responses 2800 subjects. item answered six point Likert scale ranging 1 (inaccurate), 6 (accurate). Gender coded 0 male 1 female. Missing values addressed using mode imputation.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Agreeableness and Gender Data — part_bfi","text":"","code":"data(part_bfi)"},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Agreeableness and Gender Data — part_bfi","text":"object class \"data.frame\" 2800 observations following 6 variables: A1 indifferent feelings others. A2 Inquire others' well-. A3 Know comfort others. A4 Love children. A5 Make people feel ease. gender Gender respondent.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Agreeableness and Gender Data — part_bfi","text":"International Personality Item Pool (https://ipip.ori.org) https://search.r-project.org/CRAN/refmans/psychTools/html/bfi.html","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Agreeableness and Gender Data — part_bfi","text":"Revelle, W. (2024). Psych: Procedures Psychological, Psychometric, Personality Research. Evanston, Illinois: Northwestern University. https://CRAN.R-project.org/package=psych","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/part_bfi.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Agreeableness and Gender Data — part_bfi","text":"","code":"data(part_bfi) head(part_bfi) #> A1 A2 A3 A4 A5 gender #> 61617 2 4 3 4 4 0 #> 61618 2 4 5 2 5 1 #> 61620 5 4 5 4 4 1 #> 61621 4 4 6 5 5 1 #> 61622 2 3 3 4 5 0 #> 61623 6 6 5 6 5 1"},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot Transformation — plot_likert_transform","title":"Plot Transformation — plot_likert_transform","text":"Plots densities latent variables corresponding transformed discrete probability distributions.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot Transformation — plot_likert_transform","text":"","code":"plot_likert_transform(n_items, n_levels, mean = 0, sd = 1, skew = 0)"},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot Transformation — plot_likert_transform","text":"n_items number Likert scale items (questions). n_levels number response categories Likert item. Integer vector integers. mean means latent variables. Numeric vector numerics. Defaults 0. sd standard deviations latent variables. Numeric vector numerics. Defaults 1. skew marginal skewness latent variables. Numeric vector numerics. Defaults 0.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot Transformation — plot_likert_transform","text":"NULL. function produces plot.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/plot_likert_transform.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot Transformation — plot_likert_transform","text":"","code":"plot_likert_transform(n_items = 3, n_levels = c(3, 4, 5)) plot_likert_transform(n_items = 3, n_levels = 5, mean = c(0, 1, 2)) plot_likert_transform(n_items = 3, n_levels = 5, sd = c(0.8, 1, 1.2)) plot_likert_transform(n_items = 3, n_levels = 5, skew = c(-0.5, 0, 0.5))"},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculate Response Proportions — response_prop","title":"Calculate Response Proportions — response_prop","text":"Returns table proportions possible response category.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculate Response Proportions — response_prop","text":"","code":"response_prop(data, n_levels)"},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculate Response Proportions — response_prop","text":"data numeric vector matrix responses. n_levels number response categories.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculate Response Proportions — response_prop","text":"table response category proportions.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/response_prop.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Calculate Response Proportions — response_prop","text":"","code":"data <- c(1, 2, 2, 3, 3, 3) response_prop(data, n_levels = 3) #> 1 2 3 #> 0.1666667 0.3333333 0.5000000 data_matrix <- matrix(c(1, 2, 2, 3, 3, 3), ncol = 2) response_prop(data_matrix, n_levels = 3) #> Response #> Item 1 2 3 #> [1,] 0.3333333 0.6666667 0 #> [2,] 0.0000000 0.0000000 1"},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate Random Responses — rlikert","title":"Generate Random Responses — rlikert","text":"Generates array random responses Likert-type questions based specified latent variables.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate Random Responses — rlikert","text":"","code":"rlikert(size, n_items, n_levels, mean = 0, sd = 1, skew = 0, corr = 0)"},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate Random Responses — rlikert","text":"size number observations. n_items number Likert scale items (number questions). n_levels number response categories item. Integer vector integers. mean means latent variables. Numeric vector numerics. Defaults 0. sd standard deviations latent variables. Numeric vector numerics. Defaults 1. skew marginal skewness latent variables. Numeric vector numerics. Defaults 0. corr correlations latent variables. Can single numeric value representing correlation pairs, actual correlation matrix. Defaults 0.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate Random Responses — rlikert","text":"matrix random responses dimensions size n_items. column names Y1, Y2, ..., Yn n number items. entry matrix represents Likert scale response, ranging 1 n_levels.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/rlikert.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Generate Random Responses — rlikert","text":"","code":"# Generate responses for a single item with 5 levels rlikert(size = 10, n_items = 1, n_levels = 5) #> [1] 3 5 4 3 3 2 2 3 4 4 # Generate responses for three items with different levels and parameters rlikert( size = 10, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = 0.5 ) #> Y1 Y2 Y3 #> [1,] 3 1 3 #> [2,] 2 1 3 #> [3,] 3 4 2 #> [4,] 2 1 2 #> [5,] 2 2 2 #> [6,] 3 2 2 #> [7,] 3 4 4 #> [8,] 2 1 2 #> [9,] 2 2 4 #> [10,] 3 4 4 # Generate responses with a correlation matrix corr <- matrix(c( 1.00, -0.63, -0.39, -0.63, 1.00, 0.41, -0.39, 0.41, 1.00 ), nrow = 3) data <- rlikert( size = 1000, n_items = 3, n_levels = c(4, 5, 6), mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = corr )"},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":null,"dir":"Reference","previous_headings":"","what":"Simulate Likert Scale Item Responses — simulate_likert","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"Simulates Likert scale item responses based specified number response categories centered parameters latent variable.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"","code":"simulate_likert(n_levels, cp)"},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"n_levels number response categories Likert scale item. cp centered parameters latent variable. Named vector including mean (mu), standard deviation (sd), skewness (skew). Skewness must -0.95 0.95.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"named vector probabilities response category.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"simulation process uses following model detailed Boari Nai-Ruscone. Let \\(X\\) continuous variable interest, measured using Likert scale questions \\(K\\) response categories. observed discrete variable \\(Y\\) defined follows: $$ Y = k, \\quad \\text{ } \\ \\ x_{k - 1} < X \\leq x_{k} \\quad \\text{ } \\ \\ k = 1, \\dots, K $$ \\(x_{k}\\), \\(k = 0, \\dots, K\\) endpoints defined domain \\(X\\) : $$ -\\infty = x_{0} < x_{1} < \\dots < x_{K - 1} < x_{K} = \\infty. $$ endpoints dictate transformation density \\(f_{X}\\) \\(X\\) discrete probability distribution: $$ \\text{Pr}(Y = k) = \\int_{x_{k - 1}}^{x_{k}} f_{X}(x) \\, dx \\quad \\text{ } \\ \\ k = 1, \\dots, K. $$ continuous latent variable modeled using skew normal distribution. function simulate_likert performs following steps: Ensures centered parameters within acceptable range. Converts centered parameters direct parameters. Defines density function skew normal distribution. Computes probabilities response category using optimal endpoints.","code":""},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"Boari, G. Nai Ruscone, M. (2015). procedure simulating Likert scale item responses. Electronic Journal Applied Statistical Analysis 8(3), 288–297. doi:10.1285/i20705948v8n3p288","code":""},{"path":[]},{"path":"https://markolalovic.github.io/latent2likert/reference/simulate_likert.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Simulate Likert Scale Item Responses — simulate_likert","text":"","code":"cp <- c(mu = 0, sd = 1, skew = 0.5) simulate_likert(n_levels = 5, cp = cp) #> 1 2 3 4 5 #> 0.15995244 0.29511214 0.28435807 0.18964493 0.07093241 cp2 <- c(mu = 1, sd = 2, skew = -0.3) simulate_likert(n_levels = 7, cp = cp2) #> 1 2 3 4 5 6 7 #> 0.08311645 0.07169556 0.07928979 0.08940184 0.10477572 0.13413804 0.43758260"},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-010","dir":"Changelog","previous_headings":"","what":"Version 0.1.0","title":"Version 0.1.0","text":"Release date: 2020-10-17 Initial release (development version). Tested platforms: x86_64-pc-linux-gnu (64-bit) x86_64-w64-mingw32 (64-bit).","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-100","dir":"Changelog","previous_headings":"","what":"Version 1.0.0","title":"Version 1.0.0","text":"Release date: 2024-03-28 Added option generate correlated Likert scale items rlikert() function. Added estimate_params() function estimating parameters existing survey data. Resolved dependency issues. Reduced dependency standard R packages: mvtnorm, stats, graphics. sn package now required generating correlated responses using skew normal distribution. Added user prompts install sn package needed.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-110","dir":"Changelog","previous_headings":"","what":"Version 1.1.0","title":"Version 1.1.0","text":"Release date: 2024-06-06 Minor updates functions vignettes.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-111","dir":"Changelog","previous_headings":"","what":"Version 1.1.1","title":"Version 1.1.1","text":"Release date: 2024-06-06 Renamed package responsesR latent2likert better reflect purpose converting latent variables Likert scale responses. Improved package website documentation. Note: codebase development, finer details may change.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-121","dir":"Changelog","previous_headings":"","what":"Version 1.2.1","title":"Version 1.2.1","text":"CRAN release: 2024-06-24 Release date: 2024-06-12 Refactored code enhanced modularity maintainability. Modularized core functions improved readability. Improved structure organization codebase. Enhanced error handling various correlation input scenarios.","code":""},{"path":"https://markolalovic.github.io/latent2likert/news/index.html","id":"version-122","dir":"Changelog","previous_headings":"","what":"Version 1.2.2","title":"Version 1.2.2","text":"Release date: 2024-07-26 Exported previously internal function estimate_mean_and_sd based user feedback, now available direct use. Moved package sn Suggests. Fixed vignette building errors.","code":""}]