Skip to content

Commit

Permalink
Merge pull request #26 from sfcheung/devel
Browse files Browse the repository at this point in the history
0.0.2.0: Prepare for CRAN
  • Loading branch information
sfcheung authored Nov 1, 2024
2 parents 76bee90 + 67ddd4d commit 540dac9
Show file tree
Hide file tree
Showing 30 changed files with 500 additions and 370 deletions.
35 changes: 27 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
Package: betaselectr
Title: Selective Standardization in Structural Equation Models
Version: 0.0.1.17
Title: Betas-Select in Structural Equation Models and Linear Models
Version: 0.0.2.0
Authors@R:
c(person(given = "Shu Fai",
family = "Cheung",
role = c("aut", "cre"),
email = "shufai.cheung@gmail.com",
comment = c(ORCID = "0000-0002-9871-9448")))
Description: It computes Beta_Select, standardization in
structural equation models with only selected variables
standardized. It supports models with moderation, as well
as regression models. It can form confidence intervals
that takes into account the standardization appropriately.
comment = c(ORCID = "0000-0002-9871-9448")),
person(given = "Rong Wei",
family = "Sun",
role = c("aut"),
comment = c(ORCID = "0000-0003-0034-1422")),
person(given = "Florbela",
family = "Chang",
role = c("aut"),
comment = c(ORCID = "0009-0003-9931-501X")),
person(given = "Wendie",
family ="Yang",
role = c("ctb"),
comment = c(ORCID = "0009-0000-8388-6481")),
person(given = "Sing-Hang",
family = "Cheung",
role = c("aut"),
comment = c(ORCID = "0000-0001-5182-0752")))
Description: It computes betas-select, standardization in
structural equation models and regression models with only
selected variables standardized. It supports models with
moderation, with product terms formed after standardization.
It can also form confidence intervals that takes into account
the standardization appropriately, such as bootstrap
confidence intervals proposed by Cheung, Cheung, Lau, Hui,
and Vong (2022) <doi:10.1037/hea0001188>.
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
11 changes: 9 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# betaselectr 0.0.1.17
# betaselectr 0.0.1.19

- Added `lm_betaselect()` and related
methods and helper functions.
Expand Down Expand Up @@ -96,4 +96,11 @@
users. (0.0.1.16)

- Updated the vignettes and the `pkgdown`
site. (0.0.1.17)
site. (0.0.1.17)

- Proofread the documentation and
update meta-data. (0.0.1.18)

- Enabled more tests. (0.0.1.19)

- Prepare for CRAN. (0.0.2.0)
2 changes: 1 addition & 1 deletion R/coef_lav_betaselect.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @return
#' A numeric vector: The betas-select
#' in the object. Names of parameters
#' in the object. The names of parameters
#' follow the convention in `lavaan`.
#'
#' @param object The output of
Expand Down
11 changes: 7 additions & 4 deletions R/confint_lav_betaselect.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#' @title Confidence Interval for a
#' @title Confidence Intervals for a
#' 'lav_betaselect'-Class Object
#'
#' @description Return the confidence
#' intervals of betas-select in the
#' output of [lav_betaselect()].
#'
#' @details Details
#' (Include subjects for verbs.)
#' (Use 3rd person forms for verbs.)
#' @details
#' The type of
#' confidence intervals depends
#' on the call to [lav_betaselect()].
#' This function does not recompute
#' the confidence interval.
#'
#' @return
#' A two-column matrix of the confidence
Expand Down
49 changes: 30 additions & 19 deletions R/lav_betaselect.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Standardize Coefficients in a 'lavaan'-Model
#' @title Betas-Select in a 'lavaan'-Model
#'
#' @description Can standardize selected
#' variables in a `lavaan` model without
Expand All @@ -19,26 +19,28 @@
#'
#' - It does not standardize product
#' term, which is incorrect. Instead,
#' it compute the product term with
#' its component variables standardized.
#' it computes the product term with
#' its component variables standardized
#' first.
#'
#' - It can be used to generate bootstrap
#' confidence intervals for the
#' standardized solution. Bootstrap
#' standardized solution (Falk, 2018). Bootstrap
#' confidence interval is better than
#' doing standardization *before* fitting
#' a model because it correctly takes
#' into account the sampling variance
#' of the standard deviations. It is
#' also better than delta method
#' also better than delta-method
#' confidence interval because it takes
#' into account the usually asymmetric
#' distribution of parameters after
#' standardization.
#' standardization, such as standardized
#' loadings and correlations.
#'
#' - For comparison, it can also report
#' delta method standard errors and
#' confidence intervals.
#' delta-method standard errors and
#' confidence intervals if requested.
#'
#' ## Problems With Common Approaches
#'
Expand All @@ -50,7 +52,7 @@
#' or misleading in these conditions:
#'
#' - Dummy variables are standardized
#' and can not be interpreted as the
#' and their coefficients cannot be interpreted as the
#' difference between two groups on the
#' outcome variables.
#'
Expand All @@ -66,14 +68,14 @@
#' they are standardized (e.g., age).
#'
#' Moreover, the delta method is usually
#' used, which is suboptimal for
#' used in standardization, which is suboptimal for
#' standardization unless the sample
#' size is large. For example, the
#' size is large (Falk, 2018). For example, the
#' covariance with variables standardized
#' is a correlation, and its sampling
#' distribution is skewed unless its
#' population value is zero. However,
#' delta method confidence interval
#' delta-method confidence interval
#' for the correlation is necessarily
#' symmetric around the point estimate.
#'
Expand All @@ -92,7 +94,8 @@
#' - Intercepts not supported.
#'
#' @return
#' A data frame storing the parameter
#' A `lav_betaselect`-class object,
#' which is a data frame storing the parameter
#' estimates, similar in form to the
#' output of [lavaan::parameterEstimates()].
#'
Expand All @@ -103,9 +106,9 @@
#' @param to_standardize A string vector,
#' which should be the names of the
#' variables to be standardized.
#' Default is `".all"`, indicating all
#' Default is `".all."`, indicating all
#' variables are to be standardized
#' (but see `skip_categorical`).
#' (but see `skip_categorical_x`).
#'
#' @param not_to_standardize A string
#' vector, which should be the names
Expand All @@ -127,14 +130,15 @@
#' `to_standardize`. That is, a
#' categorical predictor will not be
#' standardized even if listed in
#' `to_standardize`, unless uses set
#' `to_standardize`, unless users set
#' this argument to `FALSE`.
#'
#' @param output The format of the
#' output. Not used because the format
#' of the print out is now controlled
#' of the printout is now controlled
#' by the `print`-method of the output
#' of this function.
#' of this function. Kept for backward
#' compatibility.
#'
#' @param std_se String. If set to `"none"`,
#' the default, standard errors will not
Expand Down Expand Up @@ -193,7 +197,7 @@
#' output.
#'
#' @param delta_method The method used
#' to compute delta method standard
#' to compute delta-method standard
#' errors. For internal use and should
#' not be changed.
#'
Expand Down Expand Up @@ -308,6 +312,13 @@
#' (2022) Improving an old way to measure moderation effect in standardized
#' units. *Health Psychology*, *41*(7), 502-505.
#' \doi{10.1037/hea0001188}
#'
#' Falk, C. F. (2018). Are robust standard errors the best approach
#' for interval estimation with nonnormal data in structural equation
#' modeling?
#' *Structural Equation Modeling: A Multidisciplinary Journal, 25*(2)
#' 244-266. \doi{10.1080/10705511.2017.1367254}

#'
#' @seealso [print.lav_betaselect()] for its print method.
#'
Expand Down
12 changes: 6 additions & 6 deletions R/lm_betaselect.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Standardize Coefficients in a
#' @title Betas-Select in a
#' Regression Model
#'
#' @description Can fit a linear regression
Expand Down Expand Up @@ -63,7 +63,7 @@
#' or misleading in these conditions:
#'
#' - Dummy variables are standardized
#' and cannot be interpreted as the
#' and their coefficients cannot be interpreted as the
#' difference between two groups on the
#' outcome variables.
#'
Expand Down Expand Up @@ -226,8 +226,7 @@
#' which should be the names of the
#' variables to be standardized.
#' Default is `NULL`, indicating all
#' variables are to be standardized
#' (but see `skip_categorical`).
#' variables are to be standardized.
#'
#' @param not_to_standardize A string
#' vector, which should be the names
Expand Down Expand Up @@ -270,7 +269,7 @@
#' parallel processing will be used to
#' do bootstrapping. Default is `FALSE`
#' because bootstrapping for models fitted
#' by [lm()] or [glm()] is rarely slow.
#' by [stats::lm()] or [stats::glm()] is rarely slow.
#' Actually, if both `parallel` and
#' `progress` are set to `TRUE`, the
#' speed may even be slower than serial
Expand Down Expand Up @@ -546,7 +545,8 @@ glm_betaselect <- function(...,
#' object.
#'
#' @details This is a helper functions
#' to be used by [lm_betaselect()]. It
#' to be used by [lm_betaselect()]
#' and [glm_betaselect()]. It
#' assumes that the variables selected
#' has been checked whether they are
#' numeric.
Expand Down
12 changes: 5 additions & 7 deletions R/lm_betaselect_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#' selected variables have been
#' standardized. If requested, it can
#' also return the regression
#' coefficients *without*
#' coefficients *before*
#' standardization.
#'
#' @return
#' A scalar vector: The estimate of
#' A numeric vector: The estimate of
#' regression coefficients.
#'
#' @param object The output of
Expand Down Expand Up @@ -288,13 +288,11 @@ vcov.glm_betaselect <- vcov.lm_betaselect
#' was requested, by default it returns
#' the percentile bootstrap confidence
#' intervals. Otherwise, it returns the
#' default confidence intervals
#' and raises a warning for the
#' standardized solution.
#' default confidence intervals.
#'
#' Support for other type of
#' confidence intervals will be
#' added.
#' confidence intervals may be
#' added in the future.
#'
#' @return
#' A *p* by 2 matrix of the confidence
Expand Down
25 changes: 13 additions & 12 deletions R/print_std_selected_lavaan.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title Print a 'lav_betaselect' Object
#'
#' @description Print method for an
#' @description Print method for a
#' 'lav_betaselect' object, which
#' is the output of
#' [lav_betaselect()].
Expand All @@ -23,8 +23,9 @@
#' which is compact but not easy to
#' read.
#'
#' @param x Object of the class
#' `std_solution_boot`.
#' @param x A `lav_betaselect`-class
#' object, such as the output of
#' [lav_betaselect()].
#'
#' @param ... Optional arguments to be
#' passed to [print()] methods.
Expand All @@ -39,43 +40,43 @@
#' printed in a format similar to
#' the printout of the output of
#' the `summary`-method of a
#' `lavaan-class` object.
#' 'lavaan'-class object.
#' If set to `"table"`, the results are
#' printed in a table
#' format similar to that of
#' [lavaan::parameterEstimates()]
#' with `output` set to `"data.frame"`.
#'
#' @param standardized_only Logical.
#' If `TRUE`, only the
#' If `TRUE`, the default, only the
#' results for the standardized solution
#' will be printed. If `FALSE`,
#' the default, then
#' then
#' the standardized solution is printed
#' alongside the unstandardized solution,
#' as in the printout of the output
#' of [summary()] of a [lavaan-class]
#' of [summary()] of a 'lavaan'-class
#' object.
#'
#' @param show_Bs.by Logical. If `TRUE`
#' and `output` is `"lavaan.printer"`, then the
#' column `"Bs.by"` is shown,
#' indicating, for each parameter, the
#' variables standardized. Otherwise,
#' this column is not shown if `output`
#' variables standardized.
#' This column is not shown if `output`
#' is not `"lavaan.printer"`.
#'
#' @param by_group If `TRUE`, the
#' default, and the model has more than
#' one groups, sections will be grouped
#' one group, sections will be grouped
#' by groups first, as in the print
#' out of `summary()` in `lavaan`.
#' If `FALSE`, then the sections will
#' be grouped by sections first.
#'
#' @param na_str The string to be used
#' for cells with `NA``. Default is
#' `" "``, a white space.
#' for cells with `NA`. Default is
#' `" "`, a whitespace.
#'
#' @param sig_stars If `TRUE`, the
#' default, symbols such as asterisks
Expand Down
Loading

0 comments on commit 540dac9

Please sign in to comment.