From f332f67a1d7de1a37a9fbc0b5694bea4db0f3cf1 Mon Sep 17 00:00:00 2001 From: Marko Lalovic Date: Fri, 26 Jul 2024 13:40:47 +0200 Subject: [PATCH] exported estimate_mean_and_sd, incremented package version to 1.2.2 --- R/estimation.R | 7 ++++++- man/estimate_mean_and_sd.Rd | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/R/estimation.R b/R/estimation.R index 31216eb..2e2bfc8 100644 --- a/R/estimation.R +++ b/R/estimation.R @@ -82,7 +82,7 @@ estimate_params <- function(data, n_levels, skew = 0) { #' Estimates the mean and standard deviation of a latent variable given the #' discrete probabilities of its observed Likert scale responses. #' -#' @param prob vector of probabilities for each response category. +#' @param prob named vector of probabilities for each response category. #' @param n_levels number of response categories for the Likert scale item. #' @param skew marginal skewness of the latent variable, defaults to 0. #' @param eps tolerance for convergence, defaults to 1e-6. @@ -90,6 +90,11 @@ estimate_params <- function(data, n_levels, skew = 0) { #' #' @return A numeric vector with two elements: the estimated mean and #' standard deviation. +#' +#' @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) #' #' @details #' This function uses an iterative algorithm to solve the system of non-linear diff --git a/man/estimate_mean_and_sd.Rd b/man/estimate_mean_and_sd.Rd index a55d5e5..23d4af4 100644 --- a/man/estimate_mean_and_sd.Rd +++ b/man/estimate_mean_and_sd.Rd @@ -7,7 +7,7 @@ estimate_mean_and_sd(prob, n_levels, skew = 0, eps = 1e-06, maxit = 100) } \arguments{ -\item{prob}{vector of probabilities for each response category.} +\item{prob}{named vector of probabilities for each response category.} \item{n_levels}{number of response categories for the Likert scale item.} @@ -32,3 +32,9 @@ variable and the observed discrete probability distribution of Likert scale responses. The algorithm ensures stability by reparameterizing the system and applying constraints to prevent stepping into invalid regions. } +\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) + +}