### Install piecewiseSEM Source: http://jslefche.github.io/piecewiseSEM/index.html Commands to install the package from CRAN or the development version from GitHub. ```R install.packages("piecewiseSEM") ``` ```R devtools::install_github("jslefche/piecewiseSEM@devel") ``` -------------------------------- ### Data Sets Source: http://jslefche.github.io/piecewiseSEM/reference/index.html Included datasets for examples and testing. ```APIDOC ## keeley ### Description Data set from Grace & Keeley (2006). ### Method Dataset ### Endpoint N/A (R dataset) ### Parameters None ### Request Example ```R data(keeley) ``` ### Response #### Success Response (200) - **data.frame** - The keeley dataset. #### Response Example ```R # Example output: A data frame with columns like 'biomass', 'density', etc. ``` ## meadows ### Description Data set from Grace & Jutila (1999). ### Method Dataset ### Endpoint N/A (R dataset) ### Parameters None ### Request Example ```R data(meadows) ``` ### Response #### Success Response (200) - **data.frame** - The meadows dataset. #### Response Example ```R # Example output: A data frame with relevant ecological data. ``` ## shipley ### Description Data set from Shipley (2006). ### Method Dataset ### Endpoint N/A (R dataset) ### Parameters None ### Request Example ```R data(shipley) ``` ### Response #### Success Response (200) - **data.frame** - The shipley dataset. #### Response Example ```R # Example output: A data frame with variables from Shipley (2006). ``` ``` -------------------------------- ### Perform ANOVA and model comparison Source: http://jslefche.github.io/piecewiseSEM/reference/anova.psem.html Examples demonstrating how to compute type II ANOVA for a single model and perform a Likelihood Ratio Test (LRT) between two psem models. ```R data(keeley) mod1 <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), lm(firesev ~ age, data = keeley), data = keeley ) # get type II Anova anova(mod1) #> Response Predictor Test.Stat DF P.Value #> rich cover 2200.1 1 0.0015 ** #> cover firesev 1.7 1 0.0000 *** #> firesev age 50.1 1 0.0000 *** #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 # conduct LRT mod2 <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), age ~ 1, data = keeley ) anova(mod1, mod2) #> Chi-square Difference Test #> #> Df AIC K n Chisq Chisq.diff Df.diff P.value #> mod1 3 1103.492 9 90 11.313 #> vs mod2 3 773.453 6 90 11.313 0 0 1 #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 ``` -------------------------------- ### Calculate R-squared for various models Source: http://jslefche.github.io/piecewiseSEM/reference/rsquared.html Examples demonstrating how to compute R-squared for linear, GLM, GLS, and mixed-effects models. ```R if (FALSE) { # \dontrun{ # Create data dat <- data.frame( ynorm = rnorm(100), ypois = rpois(100, 100), x1 = rnorm(100), random = letters[1:5] ) # Get R2 for linear model rsquared(lm(ynorm ~ x1, dat)) # Get R2 for generalized linear model rsquared(glm(ypois ~ x1, "poisson", dat)) rsquared(glm(ypois ~ x1, "poisson", dat), method = "mcfadden") # McFadden R2 # Get R2 for generalized least-squares model rsquared(gls(ynorm ~ x1, dat)) # Get R2 for linear mixed effects model (nlme) rsquared(nlme::lme(ynorm ~ x1, random = ~ 1 | random, dat)) # Get R2 for linear mixed effects model (lme4) rsquared(lme4::lmer(ynorm ~ x1 + (1 | random), dat)) # Get R2 for generalized linear mixed effects model (lme4) rsquared(lme4::glmer(ypois ~ x1 + (1 | random), family = poisson, dat)) rsquared(lme4::glmer(ypois ~ x1 + (1 | random), family = poisson, dat), method = "delta") # Get R2 for generalized linear mixed effects model (glmmPQL) rsquared(MASS::glmmPQL(ypois ~ x1, random = ~ 1 | random, family = poisson, dat)) # Get R2 for generalized additive models (gam) rsquared(mgcv::gam(ynorm ~ x1, dat)) } # } ``` -------------------------------- ### Example Usage of cerror Source: http://jslefche.github.io/piecewiseSEM/reference/cerror.html Demonstrates calculating correlated errors for exogenous and endogenous variables within a psem object. ```R # Generate example data dat <- data.frame(x1 = runif(50), x2 = runif(50), y1 = runif(50), y2 = runif(50)) # Create list of structural equations sem <- psem( lm(y1 ~ x1 + x2, dat), lm(y2 ~ y1 + x1, dat) ) # Look at correlated error between x1 and x2 # (exogenous) cerror(x1 %~~% x2, sem, dat) #> Response Predictor Estimate Std.Error DF Crit.Value P.Value #> df ~~x1 ~~x2 -0.1203926 NA 48 -0.840216 0.4049531 # Same as cor.test with(dat, cor.test(x1, x2)) #> #> Pearson's product-moment correlation #> #> data: x1 and x2 #> t = -0.84022, df = 48, p-value = 0.405 #> alternative hypothesis: true correlation is not equal to 0 #> 95 percent confidence interval: #> -0.3858114 0.1634319 #> sample estimates: #> cor #> -0.1203926 #> # Look at correlatde error between x1 and y1 # (endogenous) cerror(y1 %~~% x1, sem, dat) #> Error in eval(mf, parent.frame()): object 'dat' not found # Not the same as cor.test # (accounts for influence of x1 and x2 on y1) with(dat, cor.test(y1, x1)) #> #> Pearson's product-moment correlation #> #> data: y1 and x1 #> t = -0.91341, df = 48, p-value = 0.3656 #> alternative hypothesis: true correlation is not equal to 0 #> 95 percent confidence interval: #> -0.3946960 0.1532138 #> sample estimates: #> cor #> -0.1307082 #> # Specify in psem sem <- update(sem, x1 %~~% y1) coefs(sem) #> Error in eval(mf, parent.frame()): object 'dat' not found ``` -------------------------------- ### Multigroup Analysis Example Source: http://jslefche.github.io/piecewiseSEM/reference/multigroup.html Example usage of the multigroup function with the meadows dataset to compare structural equation models across groups. ```R data(meadows) jutila <- psem( lm(rich ~ elev + mass, data = meadows), lm(mass ~ elev, data = meadows) ) jutila.multigroup <- multigroup(jutila, group = "grazed") jutila.multigroup ``` -------------------------------- ### Customize psem plot attributes Source: http://jslefche.github.io/piecewiseSEM/reference/plot.psem.html Example of overriding default node attributes for a customized visualization. ```R plot(mod, node_attrs = list( shape = "rectangle", color = "black", fillcolor = "orange", x = 3, y=1:4)) ``` -------------------------------- ### GET /data/keeley Source: http://jslefche.github.io/piecewiseSEM/reference/keeley.html Retrieves the Keeley dataset, which consists of 90 observations of 8 variables related to plant species richness and fire severity. ```APIDOC ## GET /data/keeley ### Description Retrieves the Keeley dataset from the piecewisesem project, containing 90 observations of 8 variables. ### Method GET ### Endpoint /data/keeley ### Response #### Success Response (200) - **distance** (numeric) - Distance to coast - **elev** (numeric) - Elevation from sea level - **abiotic** (numeric) - Abiotic favorability - **age** (numeric) - Age of stand before fire - **hetero** (numeric) - Plot heterogeneity - **firesev** (numeric) - Severity of fire - **cover** (numeric) - Cover of plants - **rich** (numeric) - Plant species richness ``` -------------------------------- ### Print anova.psem object Source: http://jslefche.github.io/piecewiseSEM/reference/print.anova.psem.html This is the S3 method for printing an object of class 'anova.psem'. It takes the object 'x' and additional arguments. No specific setup is required beyond having an 'anova.psem' object. ```R # S3 method for class 'anova.psem' print(x, ...) ``` -------------------------------- ### Get Sorted PSEM Object in DAG Order Source: http://jslefche.github.io/piecewiseSEM/reference/getSortedPsem.html The getSortedPsem function takes a psem object, extracts its Directed Acyclic Graph (DAG), and then sorts the psem object according to the DAG's order (from exogenous to terminal endogenous variables). This sorted object is suitable for use by other functions within the package. Note that correlated errors are removed by this function. ```APIDOC ## getSortedPsem ### Description Takes a [psem] object, pulls out the DAG, and then sorts the psem object into the order of the DAG (from exogenous to terminal endogenous variable) for use by other functions. Note: removes correlated errors. ### Arguments - **object** (psem) - A fit [psem] object - **keepdata** (logical) - Defaults to TRUE. Should the data with the psem be included in the returned object? ### Value A new [psem] object, without the data. ``` -------------------------------- ### Get residuals from psem object Source: http://jslefche.github.io/piecewiseSEM/reference/residuals.psem.html Use the `residuals` function on a `psem` object to obtain a data frame of residuals for endogenous variables. No additional arguments are typically needed beyond the `psem` object itself. ```R # S3 method for class 'psem' residuals(object, ...) ``` -------------------------------- ### anova.psem Source: http://jslefche.github.io/piecewiseSEM/reference/anova.psem.html Computes an analysis of variance table for one or more structural equation models. It can be used to get Type II ANOVA tables for a single model or Chi-squared difference tests for comparing multiple models. ```APIDOC ## anova.psem ### Description Compute analysis of variance table for one or more structural equation models. ### Method S3 method for class 'psem' ### Endpoint N/A (R function) ### Parameters #### Arguments - **object** (psem) - a `psem` object - **...** (any) - additional objects of the same type - **digits** (numeric) - number of digits to round results. Default is 3 - **anovafun** (function) - The function used for ANOVA. Defaults to `Anova` ### Value An F, LRT, or other table for a single model, or a list of comparisons between multiple models. ### Details Additional models will be tested against the first model using a Chi-squared difference test. ### See also `Anova` ### Examples ```R data(keeley) mod1 <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), lm(firesev ~ age, data = keeley), data = keeley ) # get type II Anova anova(mod1) # conduct LRT mod2 <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), age ~ 1, data = keeley ) anova(mod1, mod2) ``` ``` -------------------------------- ### Construct and Summarize SEM Source: http://jslefche.github.io/piecewiseSEM/index.html Demonstrates creating a structural equation model using psem and generating summaries with various conflict resolution options. ```R # Load library library(piecewiseSEM) # Create fake data set.seed(1) data <- data.frame( x = runif(100), y1 = runif(100), y2 = rpois(100, 1), y3 = runif(100) ) # Create SEM using `psem` modelList <- psem( lm(y1 ~ x, data), glm(y2 ~ x, "poisson", data), lm(y3 ~ y1 + y2, data), data ) # Run summary summary(modelList) # Address conflict using conserve = T summary(modelList, conserve = T) # Address conflict using direction = c() summary(modelList, direction = c("y2 <- y1")) # Address conflict using correlated errors modelList2 <- update(modelList, y2 %~~% y1) summary(modelList2) ``` -------------------------------- ### Initialize a psem object Source: http://jslefche.github.io/piecewiseSEM/reference/psem.html Basic syntax for creating a psem object from a list of structural equations. ```R psem(...) ``` -------------------------------- ### Create and summarize a piecewise SEM Source: http://jslefche.github.io/piecewiseSEM/reference/psem.html Constructs a model using linear regressions and displays the summary statistics including goodness-of-fit and coefficients. ```R mod <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), lm(firesev ~ age, data = keeley), data = keeley ) summary(mod) ``` -------------------------------- ### Package Information Source: http://jslefche.github.io/piecewiseSEM/reference/index.html Information about the piecewiseSEM package. ```APIDOC ## piecewiseSEM `piecewiseSEM-package` ### Description The 'piecewiseSEM' package. ### Method Package ### Endpoint N/A (R package) ### Parameters None ### Request Example ```R library(piecewiseSEM) ``` ### Response #### Success Response (200) - **package loaded** - The piecewiseSEM package is loaded into the R session. #### Response Example ```R # No direct output, but functions from the package become available. ``` ## import ### Description Functions to import from dependencies. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R # Example: import(dependency_package) ``` ### Response #### Success Response (200) - **imported functions** - Functions from dependent packages are made available. #### Response Example ```R # No direct output, but functions become accessible. ``` ``` -------------------------------- ### S3 method summary(psem) Source: http://jslefche.github.io/piecewiseSEM/reference/summary.psem.html Returns a list of summary statistics for a piecewise structural equation model object. ```APIDOC ## S3 method summary(psem) ### Description Returns information necessary to interpret piecewise structural equation models, including tests of directed separation, path coefficients, information criterion values, and R-squared values of individual models. ### Parameters #### Request Body - **object** (list) - Required - A list of structural equations. - **basis.set** (optional) - Optional - An optional basis set. - **direction** (vector) - Optional - A vector of claims defining the specific directionality of any independence claim(s). - **interactions** (boolean) - Optional - Whether interactions should be included in independence claims. Default is FALSE. - **conserve** (boolean) - Optional - Whether the most conservative P-value should be returned. Default is FALSE. - **conditioning** (boolean) - Optional - Whether all conditioning variables should be shown in the table. Default is FALSE. - **add.claims** (vector) - Optional - An optional vector of additional independence claims to be added to the basis set. - **standardize** (string) - Optional - Whether standardized path coefficients should be reported. Default is "scale". - **standardize.type** (string) - Optional - The type of standardized for non-Gaussian responses: "latent.linear" (default), "Mendard.OE". - **test.statistic** (string) - Optional - The type of test statistic generated by Anova. Default is "F". - **test.type** (string) - Optional - The type of test ("II" or "III") for significance of categorical variables. Default is "II". - **intercepts** (boolean) - Optional - Whether intercepts should be included in the coefficient table. Default is FALSE. - **AIC.type** (string) - Optional - Whether the log-likelihood "loglik" or d-sep "dsep" AIC score should be reported. Default is "loglik". - **.progressBar** (boolean) - Optional - An optional progress bar. Default is TRUE. ### Response #### Success Response (200) - **dTable** (table) - A summary table of the tests of directed separation. - **CStat** (object) - Fisher's C statistic, degrees of freedom, and significance value. - **AIC** (object) - Information criterion (Akaike, corrected Akaike) as well as degrees of freedom and sample size. - **coefficients** (table) - A summary table of the path coefficients. - **R2** (list) - (Pseudo)-R2 values. ``` -------------------------------- ### fisherC Function Documentation Source: http://jslefche.github.io/piecewiseSEM/reference/fisherC.html This snippet provides detailed documentation for the fisherC function, including its arguments, return value, and purpose. ```APIDOC ## fisherC Function ### Description Summarize tests of directed separation using Fisher's C statistic. ### Method Function Call ### Endpoint N/A (R function) ### Parameters #### Arguments - **dTable** (data.frame) - a `data.frame` containing tests of directed separation from `dSep` - **add.claims** (vector, optional) - an optional vector of additional independence claims (i.e., P-values) to be added to the basis set - **basis.set** (list, optional) - An optional list of independence claims. - **direction** (vector, optional) - a vector of claims defining the specific directionality of any independence claim(s) - **interactions** (boolean) - whether interactions should be included in independence claims. Default is FALSE - **conserve** (boolean) - whether the most conservative P-value should be returned. Default is FALSE - **conditional** (boolean) - whether the conditioning variables should be shown in the table. Default is FALSE - **.progressBar** (boolean) - an optional progress bar. Default is FALSE ### Value a data.frame corresponding to the C statistic, d.f., and P-value ``` -------------------------------- ### Print psem Object Source: http://jslefche.github.io/piecewiseSEM/reference/print.psem.html This snippet shows the S3 method for printing objects of class 'psem'. It outlines the function signature and its arguments. ```APIDOC ## Print psem Object ### Description Prints an object of class 'psem'. ### Method S3 method for class 'psem' ### Endpoint N/A (R function) ### Parameters #### Arguments - **x** (object of class psem) - Description: The object to be printed. - **...** (any) - Description: Further arguments passed to or from other methods. ### Request Example N/A (R function) ### Response N/A (R function - prints to console) ``` -------------------------------- ### S3 method print.basisSet Source: http://jslefche.github.io/piecewiseSEM/reference/print.basisSet.html Prints the contents of a basis set object. ```APIDOC ## S3 method print.basisSet ### Description Prints a basis set object to the console. ### Method S3 Method ### Parameters #### Arguments - **x** (basisSet) - Required - A basis set object. - **...** (dots) - Optional - Further arguments passed to or from other methods. ``` -------------------------------- ### Print Summary of psem Object Source: http://jslefche.github.io/piecewiseSEM/reference/print.summary.psem.html This is an S3 method for printing summary objects of class 'summary.psem'. It takes the summary object 'x' and additional arguments. ```R # S3 method for class 'summary.psem' print(x, ...) ``` -------------------------------- ### POST /coefs Source: http://jslefche.github.io/piecewiseSEM/reference/coefs.html Extracts standardized path coefficients from a psem model object. ```APIDOC ## POST /coefs ### Description Extracts (standardized) path coefficients from a psem object, returning a data.frame of coefficients, standard errors, degrees of freedom, and significance tests. ### Method POST ### Parameters #### Request Body - **modelList** (list) - Required - A list of structural equations, or a model. - **standardize** (string) - Optional - The type of standardization: 'none', 'scale', 'range'. Default is 'scale'. - **standardize.type** (string) - Optional - The type of standardization for non-Gaussian responses: 'latent.linear', 'Menard.OE'. Default is 'latent.linear' for binomial; otherwise 'Menard.OE'. - **test.statistic** (string) - Optional - The type of test statistic generated by Anova. - **test.type** (string) - Optional - The type of test for significance of categorical variables from Anova. Default is 'II'. - **intercepts** (boolean) - Optional - Whether intercepts should be included in the coefficients table. Default is FALSE. ### Request Example { "modelList": "psem_object", "standardize": "scale", "intercepts": false } ### Response #### Success Response (200) - **data.frame** (object) - A table containing Response, Predictor, Estimate, Std.Error, DF, Crit.Value, P.Value, and Std.Estimate. #### Response Example { "Response": "rich", "Predictor": "cover", "Estimate": 15.6727, "Std.Error": 4.7931, "DF": 88, "Crit.Value": 3.2698, "P.Value": 0.0015, "Std.Estimate": 0.3291 } ``` -------------------------------- ### Function signature for rsquared Source: http://jslefche.github.io/piecewiseSEM/reference/rsquared.html Basic syntax for calling the rsquared function. ```R rsquared(modelList, method = NULL) ``` -------------------------------- ### Calculating and plotting partial residuals Source: http://jslefche.github.io/piecewiseSEM/reference/partialResid.html Demonstrates manual calculation of partial residuals compared to using the partialResid function. ```R # Generate data dat <- data.frame(y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100)) # Build model model <- lm(y ~ x1 + x2, dat) # Compute partial residuals of y ~ x1 yresid <- resid(lm(y ~ x2, dat)) xresid <- resid(lm(x1 ~ x2, dat)) plot(xresid, yresid) # Use partialResid presid <- partialResid(y ~ x1, model) #> Error in eval(mf, parent.frame()): object 'dat' not found with(presid, plot(xresid, yresid)) # identical plot! #> Error: object 'presid' not found ``` -------------------------------- ### Print Summary for psem Objects Source: http://jslefche.github.io/piecewiseSEM/reference/print.summary.psem.html This snippet shows the S3 method for printing the summary of a piecewise structural equation model (psem) object. ```APIDOC ## Print Summary for psem Objects ### Description This S3 method is used to print the summary of an object of class `summary.psem`. ### Method S3 Method ### Endpoint N/A (R function) ### Parameters #### Arguments - **x** (summary.psem) - Required - An object of class `summary.psem`. - **...** (any) - Optional - Further arguments passed to or from other methods. ### Request Example ```R # Assuming 'model' is a fitted psem object summary_model <- summary(model) print(summary_model) ``` ### Response #### Success Response Prints the summary of the psem object to the console. #### Response Example ``` # Example output structure (actual output may vary) # Call: # psem(...) # # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 1.2345 0.1234 10.00 0.0000 # ... # # R-squared: # ... ``` ``` -------------------------------- ### Generate psem path diagram Source: http://jslefche.github.io/piecewiseSEM/reference/plot.psem.html Basic usage of the plot function on a fitted psem model. ```R data(keeley) mod <- psem( lm(rich ~ cover, data=keeley), lm(cover ~ firesev, data=keeley), lm(firesev ~ age, data=keeley), data = keeley ) plot(mod) ``` -------------------------------- ### S3 method print.multigroup.psem Source: http://jslefche.github.io/piecewiseSEM/reference/print.multigroup.psem.html Prints the summary or details of a multigroup piecewise structural equation model object. ```APIDOC ## S3 method print.multigroup.psem ### Description Prints an object of class 'multigroup.psem' to the console. ### Method S3 Method ### Parameters #### Arguments - **x** (multigroup.psem) - Required - An object of class 'multigroup.psem' to print. - **...** (dots) - Optional - Additional arguments passed to the print function. ### Request Example print(x) ``` -------------------------------- ### Model Fitting and Summary Source: http://jslefche.github.io/piecewiseSEM/reference/index.html Functions for fitting piecewise structural equation models and summarizing their results. ```APIDOC ## psem() ### Description Fitting piecewise structural equation models. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R psem(list(y1 ~ x1 + x2, y2 ~ y1 + x3), data = mydata) ``` ### Response #### Success Response (200) - **psem object** - A fitted piecewise structural equation model object. #### Response Example ```R # Example output structure (actual output may vary) # psem object with fitted models ``` ## summary(__) ### Description Summarizing piecewise structural equation models. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R summary(my_psem_object) ``` ### Response #### Success Response (200) - **summary object** - A summary of the fitted psem object. #### Response Example ```R # Example output structure (actual output may vary) # Summary statistics, coefficients, model fit indices ``` ``` -------------------------------- ### plot.psem Source: http://jslefche.github.io/piecewiseSEM/reference/plot.psem.html Generates a path diagram for a piecewiseSEM object. ```APIDOC ## plot.psem ### Description Generates path diagrams of piecewiseSEM fits using DiagrammeR. ### Method S3 method for class 'psem' ### Parameters #### Arguments - **x** (psem) - Required - A psem() object. - **return** (logical) - Optional - Whether to return the output from DiagrammeR::create_graph() for modification. - **node_attrs** (data.frame) - Optional - List of node attributes to override defaults. - **edge_attrs** (data.frame) - Optional - List of edge attributes to override defaults. - **ns_dashed** (logical) - Optional - If TRUE, non-significant paths are dashed. - **alpha** (numeric) - Optional - Alpha level for assessing significance. - **show** (character) - Optional - Type of coefficients to show ('std' for standardized, 'unstd' for unstandardized). - **digits** (numeric) - Optional - Number of significant digits to display. - **add_edge_label_spaces** (logical) - Optional - Whether to add spaces around edge labels. - **...** (dots) - Optional - Other arguments passed to DiagrammeR::render_graph(). ### Response - **Value** (DiagrammeR::dgr_graph) - Returns an object of class DiagrammeR::dgr_graph. ``` -------------------------------- ### Define ANOVA method for psem objects Source: http://jslefche.github.io/piecewiseSEM/reference/anova.psem.html S3 method signature for performing ANOVA on psem objects. ```R # S3 method for class 'psem' anova(object, ..., digits = 3, anovafun = "Anova") ``` -------------------------------- ### Plotting and Printing Source: http://jslefche.github.io/piecewiseSEM/reference/index.html Functions for visualizing and displaying model information. ```APIDOC ## plot(__) ### Description Plotting of Piecewise Structural Equation Models. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R plot(my_psem_object) ``` ### Response #### Success Response (200) - **plot** - A graphical representation of the SEM. #### Response Example ```R # Example output: A plot window displaying the SEM diagram ``` ## print(__) ### Description Print anova results. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R print(anova_results) ``` ### Response #### Success Response (200) - **formatted text** - A printed representation of anova results. #### Response Example ```R # Example output: A formatted table of ANOVA results ``` ## print(__) ### Description Print basis set. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R print(basis_set) ``` ### Response #### Success Response (200) - **formatted text** - A printed representation of the basis set. #### Response Example ```R # Example output: A printed basis set ``` ## print(__) ### Description Print multigroup analysis results. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R print(multigroup_results) ``` ### Response #### Success Response (200) - **formatted text** - A printed representation of multigroup results. #### Response Example ```R # Example output: A printed summary of multigroup analysis ``` ## print(__) ### Description Print psem object. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R print(my_psem_object) ``` ### Response #### Success Response (200) - **formatted text** - A printed representation of the psem object. #### Response Example ```R # Example output: A printed summary of the psem object ``` ## print(__) ### Description Print summary of psem object. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R print(summary_object) ``` ### Response #### Success Response (200) - **formatted text** - A printed representation of the summary. #### Response Example ```R # Example output: A printed summary of the psem object ``` ``` -------------------------------- ### Data Handling and Utilities Source: http://jslefche.github.io/piecewiseSEM/reference/index.html Functions for data manipulation and utility operations. ```APIDOC ## as.psem() ### Description Convert list to psem object. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R as.psem(list_of_models) ``` ### Response #### Success Response (200) - **psem object** - A psem object created from the list. #### Response Example ```R # Example output: A psem object ``` ## cbind_fill() ### Description Bind data.frames of differing dimensions. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R cbind_fill(df1, df2) ``` ### Response #### Success Response (200) - **data.frame** - A combined data frame with filled missing values. #### Response Example ```R # Example output: A data frame ``` ## getDAG() ### Description Generate adjacency matrix from list of structural equations. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R getDAG(list_of_equations) ``` ### Response #### Success Response (200) - **matrix** - An adjacency matrix representing the DAG. #### Response Example ```R # Example output: A numeric matrix ``` ## getSortedPsem() ### Description Get a sorted psem object in DAG order. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R getSortedPsem(my_psem_object) ``` ### Response #### Success Response (200) - **psem object** - A sorted psem object. #### Response Example ```R # Example output: A psem object ``` ## `%~~%` ### Description Correlated error operator. ### Method Operator ### Endpoint N/A (R operator) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R y1 %~~% y2 ``` ### Response #### Success Response (200) - **expression** - Represents correlated errors in model formulas. #### Response Example ```R # Example output: y1 %~~% y2 ``` ``` -------------------------------- ### S3 Method for psem Objects in R Source: http://jslefche.github.io/piecewiseSEM/reference/summary.psem.html This is the S3 method for the 'psem' class, used for summarizing piecewise structural equation models. It includes numerous arguments to control the output and analysis. ```r summary( object, ..., basis.set = NULL, direction = NULL, interactions = FALSE, conserve = FALSE, conditioning = FALSE, add.claims = NULL, standardize = "scale", standardize.type = "latent.linear", test.statistic = "F", test.type = "II", intercepts = FALSE, AIC.type = "loglik", .progressBar = TRUE ) ``` -------------------------------- ### Model Evaluation and Comparison Source: http://jslefche.github.io/piecewiseSEM/reference/index.html Functions for evaluating and comparing piecewise structural equation models. ```APIDOC ## AIC(__) ### Description Generic function for SEM AIC(c) score. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R AIC(my_psem_object) ``` ### Response #### Success Response (200) - **numeric** - AIC score for the model. #### Response Example ```R # Example output: 150.75 ``` ## AIC_psem() ### Description Information criterion values for SEM. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R AIC_psem(my_psem_object) ``` ### Response #### Success Response (200) - **numeric vector** - Information criterion values. #### Response Example ```R # Example output: c(AIC = 150.75, BIC = 165.20) ``` ## anova(__) ### Description ANOVA and chi-squared difference test for model comparison. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R anova(psem1, psem2) ``` ### Response #### Success Response (200) - **anova table** - Results of the ANOVA and chi-squared difference test. #### Response Example ```R # Example output structure (actual output may vary) # Table comparing models with chi-squared differences ``` ## dSep() ### Description Tests of directed separation. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R dSep(my_psem_object) ``` ### Response #### Success Response (200) - **list** - Results of directed separation tests. #### Response Example ```R # Example output structure (actual output may vary) # List of tests and their significance ``` ## fisherC() ### Description Summarize tests of directed separation using Fisher's C statistic. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R fisherC(my_psem_object) ``` ### Response #### Success Response (200) - **numeric** - Fisher's C statistic. #### Response Example ```R # Example output: 0.95 ``` ## LLchisq() ### Description Generalized chi-squared for piecewise SEM. ### Method Function ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```R LLchisq(my_psem_object) ``` ### Response #### Success Response (200) - **numeric** - Generalized chi-squared value. #### Response Example ```R # Example output: 25.5 ``` ``` -------------------------------- ### Implement correlated errors in psem Source: http://jslefche.github.io/piecewiseSEM/reference/grapes-twiddle-twiddle-grapes.html Demonstrates creating a structural equation model and applying the correlated error operator to analyze relationships between variables. ```R # Generate example data dat <- data.frame(x1 = runif(50), x2 = runif(50), y1 = runif(50), y2 = runif(50)) # Create list of structural equations sem <- psem( lm(y1 ~ x1 + x2, dat), lm(y2 ~ y1 + x1, dat) ) # Look at correlated error between x1 and x2 # (exogenous) cerror(x1 %~~% x2, sem, dat) #> Response Predictor Estimate Std.Error DF Crit.Value P.Value #> df ~~x1 ~~x2 0.1405071 NA 48 0.9832156 0.3304315 # Same as cor.test with(dat, cor.test(x1, x2)) #> #> Pearson's product-moment correlation #> #> data: x1 and x2 #> t = 0.98322, df = 48, p-value = 0.3304 #> alternative hypothesis: true correlation is not equal to 0 #> 95 percent confidence interval: #> -0.143451 0.403090 #> sample estimates: #> cor #> 0.1405071 #> # Look at correlatde error between x1 and y1 # (endogenous) cerror(y1 %~~% x1, sem, dat) #> Error in eval(mf, parent.frame()): object 'dat' not found # Not the same as cor.test # (accounts for influence of x1 and x2 on y1) with(dat, cor.test(y1, x1)) #> #> Pearson's product-moment correlation #> #> data: y1 and x1 #> t = 0.2769, df = 48, p-value = 0.783 #> alternative hypothesis: true correlation is not equal to 0 #> 95 percent confidence interval: #> -0.2410929 0.3147834 #> sample estimates: #> cor #> 0.03993473 #> # Specify in psem sem <- update(sem, x1 %~~% y1) coefs(sem) #> Error in eval(mf, parent.frame()): object 'dat' not found ``` -------------------------------- ### Extract Path Coefficients Source: http://jslefche.github.io/piecewiseSEM/reference/coefs.html Use coefs() to extract standardized path coefficients from a psem object. Ensure the psem object is created and passed as the first argument. Standardization and testing options can be customized. ```R coefs( modelList, standardize = "scale", standardize.type = "latent.linear", test.statistic = "F", test.type = "II", intercepts = FALSE ) ``` ```R mod <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), lm(firesev ~ age, data = keeley), data = keeley ) coefs(mod) ``` -------------------------------- ### Calculate AIC for psem models Source: http://jslefche.github.io/piecewiseSEM/reference/AIC.psem.html Demonstrates calculating AIC scores for a psem model using both log-likelihood and d-sep methods. ```R mod <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), lm(firesev ~ age, data = keeley), data = keeley ) # Get log-likelihood based AIC AIC(mod) #> AIC K n #> 1 1103.492 9 90 # Get d-sep based AIC AIC(mod, AIC.type = "dsep") #> AIC K n #> 1 35.136 9 90 ``` -------------------------------- ### Derive Log-Likelihoods for Piecewise SEM Source: http://jslefche.github.io/piecewiseSEM/reference/LLchisq.html Use `LLchisq` to calculate the Chi-squared statistic, degrees of freedom, and P-value for a piecewise SEM. This function is useful for assessing model fit. ```R LLchisq( modelList, basis.set = NULL, direction = NULL, interactions = FALSE, conserve = FALSE ) ``` ```R mod <- psem( lm(rich ~ cover, data = keeley), lm(cover ~ firesev, data = keeley), lm(firesev ~ age, data = keeley), data = keeley ) LLchisq(mod) #> Chisq df P.Value #> 1 11.313 3 0.01 ``` -------------------------------- ### POST /cerror Source: http://jslefche.github.io/piecewiseSEM/reference/cerror.html Calculates partial correlations and significance tests for variables defined in a structural equation model list. ```APIDOC ## POST /cerror ### Description Calculates the (partial) correlation and associated significance test for two variables specified in a structural equation model. ### Method POST ### Endpoint /cerror ### Parameters #### Request Body - **formula.** (formula) - Required - A formula specifying the two correlated variables using the %~~% operator. - **modelList** (list) - Required - A list of structural equations. - **data** (data.frame) - Optional - A data.frame containing the data used in the list of equations. ### Response #### Success Response (200) - **data.frame** (object) - A data.frame containing the (partial) correlation, standard error, degrees of freedom, critical value, and P-value. ``` -------------------------------- ### Print ANOVA Results Source: http://jslefche.github.io/piecewiseSEM/reference/print.anova.psem.html This snippet details the S3 method for printing ANOVA results specific to the 'anova.psem' class in the PiecewiseSEM package. ```APIDOC ## Print anova.psem Results ### Description This S3 method is used to print the results of an ANOVA analysis performed on a piecewise structural equation model (psem) object. ### Method `print.anova.psem` ### Arguments * **x** (anova.psem) - Required - An object of class 'anova.psem', typically generated by an ANOVA function applied to a psem object. * **...** - Optional - Further arguments passed to or from other methods. ### Request Example ```R # Assuming 'my_psem_model' is a fitted psem object and 'anova_results' is its ANOVA table print(anova_results) ``` ### Response This method does not return a value but prints a formatted summary of the ANOVA results to the console. ```