Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft lm vignette #20

Merged
merged 9 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: betaselectr
Title: Selective Standardization in Structural Equation Models
Version: 0.0.1.11
Version: 0.0.1.12
Authors@R:
c(person(given = "Shu Fai",
family = "Cheung",
Expand Down
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# betaselectr 0.0.1.11
# betaselectr 0.0.1.12

- Added `lm_betaselect()` and related
methods and helper functions.
Expand Down Expand Up @@ -63,4 +63,8 @@

- Updated `print.summary.lm_betaselect()`
to print confidence intervals by
default, if available. (0.0.1.11)
default, if available. (0.0.1.11)

- Fixed a bug in printing the bootstrap
*p*-values for `summary.lm_betaselect()`.
(0.0.1.12)
31 changes: 30 additions & 1 deletion R/data_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,33 @@
#' summary(lm_out)
#'
#'
"data_test_mod_cat"
"data_test_mod_cat"

#' @title Test Dataset with Moderator
#' and Categorical Variables (Version 2)
#'
#' @description This dataset has one
#' predictor, one moderator, one
#' control variable, one dependent
#' variable, and a categorical variable.
#'
#' Similar to `data_test_mod_cat` but
#' generated from another population.
#'
#' @format A data frame with 500 rows
#' and five variables:
#' \describe{
#' \item{dv}{Dependent variable, continuous}
#' \item{iv}{Independent variable, continuous}
#' \item{mod}{Moderator, continuous}
#' \item{cov1}{Control variable, continuous}
#' \item{cat1}{String variable with these values: "gp1", "gp2", and "gp3"}
#' }
#'
#' @examples
#'
#' lm_out <- lm(dv ~ iv * mod + cov1 + cat1, data_test_mod_cat)
#' summary(lm_out)
#'
#'
"data_test_mod_cat2"
2 changes: 2 additions & 0 deletions R/lm_betaselect_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ summary.lm_betaselect <- function(object,
colnames(out$coefficients)[i] <- "z value"
if (boot_pvalue_type == "asymmetric") {
boot_est_list <- split(boot_est, rownames(boot_est))
boot_est_list <- boot_est_list[rownames(boot_est)]
boot_pvalues <- sapply(boot_est_list,
est2p,
h0 = 0)
Expand Down Expand Up @@ -1462,6 +1463,7 @@ summary.glm_betaselect <- function(object,
colnames(out$coefficients)[i] <- "z value"
if (boot_pvalue_type == "asymmetric") {
boot_est_list <- split(boot_est, rownames(boot_est))
boot_est_list <- boot_est_list[names(boot_est_list)]
boot_pvalues <- sapply(boot_est_list,
est2p,
h0 = 0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Not ready for use.

# betaselectr: Do selective standardization in structural equation models and regression models

(Version 0.0.1.11, updated on 2024-10-29, [release history](https://sfcheung.github.io/betaselectr/news/index.html))
(Version 0.0.1.12, updated on 2024-10-29, [release history](https://sfcheung.github.io/betaselectr/news/index.html))

It computes Beta_Select, standardization
in structural equation models with only
Expand Down
43 changes: 43 additions & 0 deletions data-raw/data_test_03.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Adapted from stdmod

set.seed(41543)
n <- 300
x <- rnorm(n)
w <- .4 * x + sqrt(1 - .4^2) * rnorm(n)
v1 <- rnorm(n)
cat1 <- sample(c("gp1", "gp2", "gp3"), n, replace = TRUE, prob = c(.2, .3, .5))
y <- .2 * x + .3 * w + .35 * x * w + .12 * v1 +
sapply(cat1,
switch,
gp1 = 0,
gp2 = .4,
gp3 = .6) +
rnorm(n, 0, 1.4)
dat <- data.frame(dv = y,
iv = x,
mod = w,
cov1 = v1,
cat1,
stringsAsFactors = FALSE)
out <- lm(dv ~ iv * mod + cov1 + cat1,
dat)
summary(out)
apply(dat[, 1:4], 2, sd)
colMeans(dat[, 1:4])
b <- 1 / c(5, 2, 4, 2)
a <- c(20, 15, 50, 20) * -b
dat0 <- scale(dat[, 1:4],
center = a,
scale = b)
dat0 <- round(dat0, 2)
apply(dat0, 2, sd)
colMeans(dat0)
apply(dat0, 2, range)
dat1 <- data.frame(dat0, cat1 = dat$cat1)
head(dat1)
out <- lm(dv ~ iv * mod + cov1 + cat1,
dat1)
summary(out)
summary(lm.beta::lm.beta(out))
data_test_mod_cat2 <- dat1
usethis::use_data(data_test_mod_cat2, overwrite = TRUE)
Binary file added data/data_test_mod_cat2.rda
Binary file not shown.
38 changes: 38 additions & 0 deletions man/data_test_mod_cat2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rebuild_vignettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ base_dir <- getwd()

setwd("vignettes/")
knitr::knit("betaselectr_lav.Rmd.original", output = "betaselectr_lav.Rmd")
knitr::knit("betaselectr_lm.Rmd.original", output = "betaselectr_lm.Rmd")

setwd(base_dir)

Expand Down
Loading
Loading