Skip to content
Open

Paper #217

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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
^references.csv
^references.yml
^R/library-references\.R$
^\.github$
99 changes: 99 additions & 0 deletions .github/workflows/rcmdcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
on:
push:
branches:
- '**'
- '!*_noci'
pull_request:
branches:
- '**'
- '!*_noci'

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
#- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}

# pandoc to check markdown files
- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
if: runner.os != 'Windows'
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: BuildWin
if: runner.os == 'Windows'
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: R CMD INSTALL --preclean --no-multiarch --with-keep.source seminr
shell: bash

- name: TestWin
if: runner.os == 'Windows'
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: devtools::test()
shell: Rscript {0}


- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,43 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project largely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.1] - 2021-03-21

### [2.0.1] Changed

- Updated the namespace to exclude MASS
- Removed the simulation of a fixture in the test-plsc-fsquared file

## [2.0.0] - 2021-02-21

### [2.0.0] Added

- S3 plot() method for visualizing all SEMinR models - CFA, CBSEM, PLS, PLSc


## [1.2.0] - 2020-12-31

### [1.2.0] Added

- A new feature to plot interaction plots
- Demo files for PLS Primer in R Workbook
- PLSpredict feature
- total paths and indirect effects
- New visualization for reliability
- Cronbachs alpha to reliability
- new datasets = corp_rep_data2 and corp_rep_data
- new method for calculating AIC and BIC
- new demonstration files for an accompanying textbook

### [1.2.0] Changed

- Changed output of summary() to generate standardized matrices and lists with an S3 print method
- Changed HOC to combine first and second stage results for outer loadings and outer weights
- Changed estimate_bootstrap() to process bootstrap matrix in a way that is naive to differences in matrix layouts

###[1.2.0] Removed
- old test fixtures for V 3.5.X (deprecated by R)

## [1.1.0] - 2020-07-01

### [1.1.0] Added
Expand Down
35 changes: 26 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
Package: seminr
Type: Package
Title: Domain-Specific Language for Building and Estimating Structural Equation Models
Version: 1.1.0
Date: 2020-07-23
Version: 2.0.1
Date: 2021-03-21
Authors@R: c(person("Soumya", "Ray", email = "[email protected]", role = c("aut", "ths")),
person("Nicholas Patrick", "Danks", email = "[email protected]", role = c("aut","cre")),
person("Juan Manuel Velasquez", "Estrada", role = "aut"),
person("James", "Uanhoro", role = "ctr", email = "[email protected]"),
person("Arturo Heynar Cano", "Bejar", role = "ctr", email = "[email protected]"))
person("André", "Calero Valdez", role = "aut", email = "[email protected]"),
person("Juan Manuel Velasquez", "Estrada", role = "ctb"),
person("James", "Uanhoro", role = "ctb", email = "[email protected]"),
person("Johannes", "Nakayama", role = "ctb", email = "[email protected]"),
person("Lilian", "Koyan", role = "ctb", email = "[email protected]"),
person("Laura", "Burbach", role = "ctb", email = "[email protected]"),
person("Arturo Heynar", "Cano Bejar", role = "ctb", email = "[email protected]"),
person("Susanne", "Adler", role = "ctb", email = "[email protected]")
)
Description: A powerful, easy to syntax for specifying and estimating complex
Structural Equation Models. Models can be estimated using Partial
Least Squares Path Modeling or Covariance-Based Structural Equation
Modeling or covariance based Confirmatory Factor Analysis.
Imports:
parallel, lavaan, MASS
parallel,
lavaan,
glue
License: GPL-3
Depends: R (>= 3.1.0)
Depends: R (>= 3.5.0)
LazyData: TRUE
RoxygenNote: 7.1.0
Suggests: knitr, testthat, rmarkdown
RoxygenNote: 7.1.1
Suggests:
knitr,
testthat,
rmarkdown,
DiagrammeR (>= 1.0.6),
DiagrammeRsvg (>= 0.1),
rsvg (>= 2.1),
webp,
semPlot,
vdiffr
VignetteBuilder: knitr
Encoding: UTF-8
45 changes: 45 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,91 @@
S3method(as.reflective,construct)
S3method(as.reflective,interaction)
S3method(as.reflective,measurement_model)
S3method(dot_graph,boot_seminr_model)
S3method(dot_graph,cbsem_model)
S3method(dot_graph,cfa_model)
S3method(dot_graph,default)
S3method(dot_graph,measurement_model)
S3method(dot_graph,pls_model)
S3method(dot_graph,specified_model)
S3method(dot_graph,structural_model)
S3method(plot,reliability_table)
S3method(plot,seminr_model)
S3method(plot,summary.predict_pls_model)
S3method(predict,seminr_model)
S3method(print,list_output)
S3method(print,measurement_model_evaluation.seminr_model)
S3method(print,seminr_theme)
S3method(print,summary.boot_seminr_model)
S3method(print,summary.cbsem_model)
S3method(print,summary.cfa_model)
S3method(print,summary.predict_pls_model)
S3method(print,summary.seminr_model)
S3method(print,table_output)
S3method(summary,boot_seminr_model)
S3method(summary,cbsem_model)
S3method(summary,cfa_model)
S3method(summary,predict_pls_model)
S3method(summary,seminr_model)
export(PLSc)
export(as.reflective)
export(associations)
export(bootstrap_model)
export(browse_plot)
export(check_test_plot)
export(composite)
export(compute_itcriteria_weights)
export(confidence_interval)
export(constructs)
export(correlation_weights)
export(csem2seminr)
export(dot_graph)
export(dot_graph_htmt)
export(edge_template_default)
export(edge_template_minimal)
export(estimate_cbsem)
export(estimate_cfa)
export(estimate_lavaan_ten_berge)
export(estimate_pls)
export(fSquared)
export(get_theme_doc)
export(higher_composite)
export(interaction_term)
export(item_errors)
export(last_seminr_plot)
export(mean_replacement)
export(mode_A)
export(mode_B)
export(multi_items)
export(node_endo_template_default)
export(node_exo_template_default)
export(orthogonal)
export(path_factorial)
export(path_weighting)
export(paths)
export(plot_htmt)
export(plot_scores)
export(predict_DA)
export(predict_EA)
export(predict_pls)
export(product_indicator)
export(reflective)
export(regression_weights)
export(relationships)
export(report_paths)
export(rho_A)
export(save_plot)
export(seminr_theme_create)
export(seminr_theme_dark)
export(seminr_theme_default)
export(seminr_theme_get)
export(seminr_theme_old)
export(seminr_theme_set)
export(seminr_theme_smart)
export(set_last_seminr_plot)
export(simplePLS)
export(single_item)
export(slope_analysis)
export(specify_model)
export(total_indirect_ci)
export(two_stage)
24 changes: 24 additions & 0 deletions R/clean_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' Function to clean data of ommitted values by mean replacement
#'
#' The \code{seminr} package provides a natural syntax for researchers to describe PLS
#' structural equation models.
#'
#' \code{mean_replacement} provides the verb for replacing all ommitted values (NA only) in the dataset with
#' the mean of the variable.
#'
#' @param data A dataset to be used for estimating a SEMinR model
#'
#' @usage
#' mean_replacement(data)
#'
#' @references Hair, J. F., Hult, G. T. M., Ringle, C. M., and Sarstedt, M. (2017). A Primer on Partial Least Squares
#' Structural Equation Modeling (PLS-SEM), 2nd Ed., Sage: Thousand Oaks.
#'
#' @export
mean_replacement <- function(data) {
for (i in 1:ncol(data)) {
colmean <- mean(data[,i][!(is.na(data[,i]))])
data[,i][is.na(data[,i])] <- colmean
}
return(data)
}
33 changes: 32 additions & 1 deletion R/compute_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ cor_rsq <- function(cor_matrix, dv_name, iv_names) {
cor_vifs <- function(cor_matrix, iv_names) {
sapply(iv_names, function(iv) {
rsq_j <- cor_rsq(cor_matrix, dv_name = iv, iv_names = iv_names[iv_names != iv])
1/(1 - rsq_j)
ret <- as.matrix(1/(1 - rsq_j))
convert_to_table_output(ret)
}, USE.NAMES = TRUE)
}

Expand All @@ -57,6 +58,24 @@ AIC_func <- function(rsq, pk, N, construct_score){
2*(pk+1)+N*log(SSerrk/N)
}

return_AIC_BIC <- function(i, seminr_model) {
antecedents <- antecedents_of(outcome = i, smMatrix = seminr_model$smMatrix)
pk <- length(antecedents)
rsq <- cor_rsq(stats::cor(seminr_model$construct_scores), dv_name = i, iv_names = antecedents)
N <- nrow(seminr_model$construct_scores)
construct_score <- seminr_model$construct_scores[,i]
construct_AIC <- AIC_func(rsq,pk,N,construct_score)
construct_BIC <- BIC_func(rsq,pk,N,construct_score)
return(c(construct_AIC, construct_BIC))
}

calculate_itcriteria <- function(seminr_model) {
endogenous <- all_endogenous(seminr_model$smMatrix)
ret <- sapply(endogenous, return_AIC_BIC, seminr_model = seminr_model)
rownames(ret) <- c("AIC", "BIC")
convert_to_table_output(ret)
}

# Computes Henseler's rhoA
compute_construct_rhoA <- function(weights, mmMatrix, construct, obsData) {
# get the weights for the construct
Expand All @@ -75,3 +94,15 @@ compute_construct_rhoA <- function(weights, mmMatrix, construct, obsData) {
return((t(w) %*% w)^2 * ((t(w) %*% (S) %*% w)/(t(w) %*% AAnondiag %*% w)))
}

#' Function to calculate Akaike weights for IT Criteria
#'
#' @param vector_of_itcriteria This argument is a vector consisting of the IT criterion estimated
#' value for each model.
#'
#' @export
compute_itcriteria_weights <- function(vector_of_itcriteria) {
delta_itcriteria <- vector_of_itcriteria - min(vector_of_itcriteria)
rel_likelihoods <- exp(-0.5 * delta_itcriteria)
sum_likelihoods <- sum(rel_likelihoods, na.rm = TRUE)
return(rel_likelihoods / sum_likelihoods)
}
Loading