knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The CodeEff_Matrix
function estimates code effects using left and right embeddings from source and target sites. This vignette demonstrates how to use this function with example data provided in the package.
Ensure the MUGS
package is loaded before running the example:
library(MUGS)
Load the required datasets for the example:
# Load required data data(S.1) data(S.2) data(U.1) data(U.2) data(X.group.source) data(X.group.target)
Prepare the variables required for the CodeEff_Matrix
function:
# Set parameters n1 <- 100 n2 <- 100 p <- 5 # Initial right embeddings V.1 <- U.1 V.2 <- U.2 # Fix rownames to ensure alignment n1.no <- n1 - 50 # if you know n.common = 50 rownames(U.1) <- as.character(seq_len(nrow(U.1))) # "1" to "n1" rownames(U.2) <- as.character(seq(from = n1.no + 1, length.out = nrow(U.2))) rownames(S.1) <- rownames(U.1) rownames(S.2) <- rownames(U.2) rownames(V.1) <- rownames(U.1) rownames(V.2) <- rownames(U.2) # Extract names and find common codes names.list.1 <- rownames(S.1) names.list.2 <- rownames(S.2) common_codes <- intersect(names.list.1, names.list.2) # Check for overlap if (length(common_codes) == 0) stop("Error: No common codes found between S.1 and S.2.") # Create zeta.int full.name.list <- c(names.list.1, names.list.2) zeta.int <- matrix(0, length(full.name.list), p) rownames(zeta.int) <- full.name.list
Run the CodeEff_Matrix
function:
# Estimate code effects CodeEff_Matrix.out <- CodeEff_Matrix( S.1=S.1, S.2=S.2, n1=n1, n2=n2, U.1=U.1, U.2=U.2, V.1=U.1, V.2=U.2, common_codes = common_codes, zeta.int = zeta.int, lambda=10, p=5 )
Explore the structure and key components of the output:
# View structure of the output str(CodeEff_Matrix.out) # Print specific components of the result cat("\nEstimated Code Effects (zeta):\n") print(CodeEff_Matrix.out$zeta[1:5, 1:3]) # Show the first 5 rows and 3 columns of zeta cat("\nFrobenius Norm Difference (dif_F):\n") print(CodeEff_Matrix.out$dif_F) cat("\nUpdated Right Embeddings for Source Site (V.1.new):\n") print(CodeEff_Matrix.out$V.1.new[1:5, 1:3]) # Show first 5 rows and 3 columns of V.1.new cat("\nUpdated Right Embeddings for Target Site (V.2.new):\n") print(CodeEff_Matrix.out$V.2.new[1:5, 1:3]) # Show first 5 rows and 3 columns of V.2.new
n1
, n2
, p
, and lambda
to test different scenarios.S.1
, S.2
, U.1
, U.2
, etc.) are correctly loaded and aligned.This vignette demonstrated how to use the CodeEff_Matrix
function for estimating code effects. Adjust input parameters and datasets to test different scenarios and interpret the output components for your analysis.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.