Skip to contents

Introduction

The jsjplot function provides comprehensive social science statistical visualization using the powerful sjPlot package. This function is designed specifically for researchers in psychology, sociology, political science, economics, and related fields who need publication-ready statistical visualizations and model summaries.

Key Features

  • Multiple Analysis Types: Regression tables, coefficient plots, interaction visualizations, marginal effects, frequency tables, correlation matrices, and PCA plots
  • Model Support: Linear models (lm), generalized linear models (glm), logistic regression, Poisson regression, and mixed effects models
  • Publication Ready: High-quality plots with extensive customization options
  • Statistical Tables: HTML-formatted regression tables with confidence intervals and significance tests
  • Performance Optimized: Intelligent caching system for faster repeated analyses
  • Comprehensive Output: Model statistics, summaries, and interpretative guidance

Installation and Setup

# Load required libraries
library(ClinicoPath)
## Warning: replacing previous import 'dplyr::as_data_frame' by
## 'igraph::as_data_frame' when loading 'ClinicoPath'
## Warning: replacing previous import 'DiagrammeR::count_automorphisms' by
## 'igraph::count_automorphisms' when loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::groups' by 'igraph::groups' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'DiagrammeR::get_edge_ids' by
## 'igraph::get_edge_ids' when loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::union' by 'igraph::union' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::union' by 'lubridate::union' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::%--%' by 'lubridate::%--%' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tnr' by 'mlr3measures::tnr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::precision' by
## 'mlr3measures::precision' when loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tn' by 'mlr3measures::tn' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fnr' by 'mlr3measures::fnr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tp' by 'mlr3measures::tp' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::npv' by 'mlr3measures::npv' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::ppv' by 'mlr3measures::ppv' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::auc' by 'mlr3measures::auc' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tpr' by 'mlr3measures::tpr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fn' by 'mlr3measures::fn' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fp' by 'mlr3measures::fp' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fpr' by 'mlr3measures::fpr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::recall' by
## 'mlr3measures::recall' when loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::specificity' by
## 'mlr3measures::specificity' when loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::sensitivity' by
## 'mlr3measures::sensitivity' when loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::as_data_frame' by
## 'tibble::as_data_frame' when loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::crossing' by 'tidyr::crossing' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'magrittr::extract' by 'tidyr::extract' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'mlr3measures::sensitivity' by
## 'caret::sensitivity' when loading 'ClinicoPath'
## Warning: replacing previous import 'mlr3measures::specificity' by
## 'caret::specificity' when loading 'ClinicoPath'
## Registered S3 methods overwritten by 'useful':
##   method         from     
##   autoplot.acf   ggfortify
##   fortify.acf    ggfortify
##   fortify.kmeans ggfortify
##   fortify.ts     ggfortify
## Warning: replacing previous import 'jmvcore::select' by 'dplyr::select' when
## loading 'ClinicoPath'
## Registered S3 methods overwritten by 'ggpp':
##   method                  from   
##   heightDetails.titleGrob ggplot2
##   widthDetails.titleGrob  ggplot2
## Warning: replacing previous import 'DataExplorer::plot_histogram' by
## 'grafify::plot_histogram' when loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'mlr3measures::auc' by 'pROC::auc' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::roc' by 'pROC::roc' when loading
## 'ClinicoPath'
## Warning: replacing previous import 'tibble::view' by 'summarytools::view' when
## loading 'ClinicoPath'
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

# Set options for better output
options(digits = 3)
knitr::opts_chunk$set(
  fig.width = 12,
  fig.height = 8,
  dpi = 300,
  out.width = "100%",
  echo = TRUE,
  eval = FALSE
)

# Check if sjPlot is available
if (!requireNamespace("sjPlot", quietly = TRUE)) {
  message("Note: sjPlot package not available. Install with: install.packages('sjPlot')")
}

Data Preparation

Let’s create realistic datasets for different types of social science analyses:

Basic Research Data

# Create comprehensive research dataset
set.seed(123)
research_data <- data.frame(
  # Continuous outcomes
  life_satisfaction = rnorm(300, 65, 15),
  academic_performance = rnorm(300, 75, 12),
  income = exp(rnorm(300, 10.5, 0.8)), # Log-normal distribution
  
  # Binary outcomes
  employment_status = rbinom(300, 1, 0.7), # 1 = employed
  college_graduate = rbinom(300, 1, 0.4),
  
  # Count outcomes
  social_activities = rpois(300, 3),
  volunteer_hours = rpois(300, 2),
  
  # Continuous predictors
  age = round(rnorm(300, 35, 12)),
  years_education = round(rnorm(300, 14, 3)),
  
  # Categorical predictors
  gender = factor(sample(c("Male", "Female"), 300, replace = TRUE)),
  marital_status = factor(sample(c("Single", "Married", "Divorced"), 
                                300, replace = TRUE, prob = c(0.4, 0.5, 0.1))),
  income_bracket = factor(sample(c("Low", "Medium", "High"), 
                                300, replace = TRUE, prob = c(0.3, 0.4, 0.3))),
  
  # Interaction variables
  treatment = factor(sample(c("Control", "Intervention"), 300, replace = TRUE)),
  baseline_score = rnorm(300, 50, 10)
) %>%
  mutate(
    # Create realistic relationships
    life_satisfaction = life_satisfaction + 
      0.2 * age + 
      2 * years_education + 
      ifelse(marital_status == "Married", 8, 0) + 
      ifelse(gender == "Female", 3, 0) + 
      rnorm(300, 0, 8),
    
    academic_performance = academic_performance + 
      1.5 * years_education + 
      ifelse(income_bracket == "High", 5, 0) + 
      rnorm(300, 0, 6),
    
    employment_status = rbinom(300, 1, plogis(-2 + 
      0.1 * years_education + 
      0.02 * age + 
      ifelse(gender == "Male", 0.3, 0)))
  )

# Display data structure
str(research_data)

Basic Usage

Coefficient Plots

The most common visualization in social science research - coefficient plots show effect sizes with confidence intervals:

# Basic coefficient plot
result_coef <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "gender", "marital_status"),
  model_type = "lm"
)

# The result contains multiple components
print(names(result_coef))

Regression Tables

Publication-ready regression tables with multiple customization options:

result_table <- jsjplot(
  data = research_data,
  analysis_type = "regression_table",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "gender", "marital_status"),
  model_type = "lm",
  show_p_values = TRUE,
  standardized = FALSE,
  confidence_level = 0.95
)

Analysis Types

1. Linear Regression Analysis

Continuous Outcomes

# Comprehensive linear model
linear_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "income_bracket", "marital_status"),
  model_type = "lm",
  show_values = TRUE,
  sort_estimates = TRUE,
  remove_intercept = TRUE,
  theme_style = "minimal"
)

Model Diagnostics and Statistics

# Same model with full statistics display
linear_stats <- jsjplot(
  data = research_data,
  analysis_type = "regression_table",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "income_bracket", "marital_status"),
  model_type = "lm",
  show_statistics = TRUE,
  show_summary = TRUE,
  html_output = TRUE
)

2. Logistic Regression Analysis

Binary Outcomes

# Logistic regression for binary outcomes
logistic_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "employment_status",
  independent_vars = c("age", "years_education", "gender", "marital_status"),
  model_type = "logistic",
  show_values = TRUE,
  colors = "colorblind",
  title = "Predictors of Employment Status"
)

Odds Ratios Visualization

# Logistic regression with transformed coefficients
odds_ratio_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "college_graduate",
  independent_vars = c("age", "years_education", "income_bracket"),
  model_type = "logistic",
  transform_axis = "log",
  show_values = TRUE,
  title = "Odds Ratios for College Graduation"
)

3. Poisson Regression Analysis

Count Outcomes

# Poisson regression for count data
poisson_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "social_activities",
  independent_vars = c("age", "life_satisfaction", "marital_status"),
  model_type = "poisson",
  show_values = TRUE,
  theme_style = "apa"
)

4. Generalized Linear Models

Different GLM Families

# Gaussian GLM (equivalent to linear regression)
gaussian_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education"),
  model_type = "glm",
  family = "gaussian"
)

# Binomial GLM for binary outcomes
binomial_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "employment_status",
  independent_vars = c("age", "years_education"),
  model_type = "glm",
  family = "binomial"
)

# Poisson GLM for count outcomes
poisson_glm_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "volunteer_hours",
  independent_vars = c("age", "life_satisfaction"),
  model_type = "glm",
  family = "poisson"
)

Advanced Features

Interaction Effects

Continuous × Categorical Interactions

# Create interaction data
interaction_data <- research_data %>%
  mutate(
    # Interaction between age and treatment
    outcome_with_interaction = baseline_score + 
      0.5 * age + 
      ifelse(treatment == "Intervention", 10, 0) + 
      # Interaction: age effect is stronger in intervention group
      ifelse(treatment == "Intervention", 0.3 * age, 0) + 
      rnorm(300, 0, 8)
  )

# Interaction plot
interaction_result <- jsjplot(
  data = interaction_data,
  analysis_type = "interaction_plot",
  dependent_var = "outcome_with_interaction",
  interaction_vars = c("age", "treatment"),
  independent_vars = c("baseline_score"),
  title = "Age × Treatment Interaction Effect"
)

Categorical × Categorical Interactions

# Interaction between gender and marital status
categorical_interaction <- jsjplot(
  data = research_data,
  analysis_type = "interaction_plot",
  dependent_var = "life_satisfaction",
  interaction_vars = c("gender", "marital_status"),
  independent_vars = c("age"),
  colors = "viridis"
)

Marginal Effects

Predicted Values and Effects

# Marginal effects visualization
marginal_result <- jsjplot(
  data = research_data,
  analysis_type = "marginal_effects",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "marital_status"),
  model_type = "lm",
  plot_type = "eff"
)

Predicted Values Plot

# Predicted values plot
predicted_result <- jsjplot(
  data = research_data,
  analysis_type = "marginal_effects",
  dependent_var = "employment_status",
  independent_vars = c("age", "years_education"),
  model_type = "logistic",
  plot_type = "pred"
)

Descriptive Analyses

Frequency Tables

Categorical Variable Analysis

# Comprehensive frequency analysis
freq_result <- jsjplot(
  data = research_data,
  analysis_type = "frequency_table"
)

Cross-Tabulations

# Create dataset with more categorical variables for better demonstration
categorical_data <- research_data %>%
  mutate(
    age_group = cut(age, breaks = c(0, 30, 50, 100), labels = c("Young", "Middle", "Older")),
    satisfaction_level = cut(life_satisfaction, 
                           breaks = c(0, 50, 70, 100), 
                           labels = c("Low", "Medium", "High"))
  )

# Frequency analysis with more categories
freq_categorical <- jsjplot(
  data = categorical_data,
  analysis_type = "frequency_table"
)

Correlation Matrices

Correlation Visualization

# Select numeric variables for correlation
numeric_vars <- research_data %>%
  select(life_satisfaction, academic_performance, age, years_education, 
         social_activities, volunteer_hours, baseline_score)

# Correlation matrix analysis
corr_result <- jsjplot(
  data = numeric_vars,
  analysis_type = "correlation_matrix"
)

Principal Component Analysis

Dimensionality Reduction

# PCA for dimensionality reduction
pca_result <- jsjplot(
  data = numeric_vars,
  analysis_type = "pca_plot"
)

High-Dimensional Data

# Create high-dimensional dataset
set.seed(456)
highdim_data <- data.frame(
  replicate(10, rnorm(200))
) %>%
  setNames(paste0("variable_", 1:10)) %>%
  mutate(
    # Create some factor structure
    factor1 = variable_1 + variable_2 + variable_3 + rnorm(200, 0, 0.5),
    factor2 = variable_4 + variable_5 + variable_6 + rnorm(200, 0, 0.5)
  )

# PCA on high-dimensional data
pca_highdim <- jsjplot(
  data = highdim_data,
  analysis_type = "pca_plot"
)

Customization and Styling

Visual Themes

Different Theme Styles

themes <- c("sjplot", "minimal", "classic", "apa", "bw")

# Demonstrate different themes (showing code for minimal theme)
theme_minimal <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "gender"),
  theme_style = "minimal",
  title = "Minimal Theme Example"
)

# APA style for publications
theme_apa <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "gender"),
  theme_style = "apa",
  title = "APA Style for Publications"
)

Color Schemes

Color-blind Friendly Options

# Color-blind safe palette
colorblind_plot <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "income_bracket"),
  colors = "colorblind",
  title = "Color-blind Friendly Plot"
)

# Viridis color scheme
viridis_plot <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "income_bracket"),
  colors = "viridis",
  title = "Viridis Color Scheme"
)

Plot Customization

Size and Spacing Options

# Customized plot appearance
custom_plot <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "gender", "marital_status"),
  dot_size = 4,
  line_size = 1.2,
  grid_breaks = 0.5,
  show_values = TRUE,
  title = "Customized Coefficient Plot",
  axis_labels = "Age,Education,Gender,Marital Status"
)

Confidence Intervals

# Different confidence levels
ci_90 <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education"),
  confidence_level = 0.90,
  title = "90% Confidence Intervals"
)

ci_99 <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education"),
  confidence_level = 0.99,
  title = "99% Confidence Intervals"
)

Advanced Statistical Options

Standardized Coefficients

Beta Coefficients

# Standardized coefficients for comparison
standardized_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "baseline_score"),
  standardized = TRUE,
  title = "Standardized Coefficients (Beta)",
  show_values = TRUE
)

# Compare with unstandardized
unstandardized_result <- jsjplot(
  data = research_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "baseline_score"),
  standardized = FALSE,
  title = "Unstandardized Coefficients",
  show_values = TRUE
)

Model Comparison

Multiple Model Types

# Linear model
linear_comparison <- jsjplot(
  data = research_data,
  analysis_type = "regression_table",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "income_bracket"),
  model_type = "lm",
  title = "Linear Model Results"
)

# GLM with Gaussian family (equivalent to linear)
glm_comparison <- jsjplot(
  data = research_data,
  analysis_type = "regression_table",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "income_bracket"),
  model_type = "glm",
  family = "gaussian",
  title = "GLM (Gaussian) Results"
)

Real-World Applications

Psychology Research Example

# Create psychology research dataset
psychology_data <- data.frame(
  participant_id = 1:250,
  # Psychological measures
  depression_score = rnorm(250, 15, 8),
  anxiety_score = rnorm(250, 12, 6),
  stress_score = rnorm(250, 18, 10),
  # Demographics
  age = round(rnorm(250, 30, 10)),
  gender = factor(sample(c("Male", "Female"), 250, replace = TRUE)),
  therapy_type = factor(sample(c("CBT", "Psychodynamic", "Control"), 250, replace = TRUE)),
  # Outcome
  wellbeing_improvement = rnorm(250, 10, 15)
) %>%
  mutate(
    # Create realistic relationships
    wellbeing_improvement = wellbeing_improvement - 
      0.3 * depression_score - 
      0.2 * anxiety_score - 
      0.1 * stress_score + 
      ifelse(therapy_type == "CBT", 8, 0) + 
      ifelse(therapy_type == "Psychodynamic", 5, 0) + 
      rnorm(250, 0, 8)
  )

# Psychology research analysis
psych_result <- jsjplot(
  data = psychology_data,
  analysis_type = "coefficient_plot",
  dependent_var = "wellbeing_improvement",
  independent_vars = c("depression_score", "anxiety_score", "therapy_type", "age"),
  model_type = "lm",
  theme_style = "apa",
  show_values = TRUE,
  title = "Predictors of Wellbeing Improvement"
)

Economics Research Example

# Create economics dataset
economics_data <- data.frame(
  # Economic indicators
  gdp_growth = rnorm(200, 2.5, 1.5),
  unemployment_rate = rnorm(200, 6, 2),
  inflation_rate = rnorm(200, 2, 1),
  # Policy variables
  fiscal_spending = rnorm(200, 20, 5),
  tax_rate = rnorm(200, 25, 8),
  # Country characteristics
  country_size = factor(sample(c("Small", "Medium", "Large"), 200, replace = TRUE)),
  region = factor(sample(c("Europe", "Asia", "Americas", "Africa"), 200, replace = TRUE)),
  # Outcome
  economic_satisfaction = rnorm(200, 60, 20)
) %>%
  mutate(
    economic_satisfaction = economic_satisfaction + 
      2 * gdp_growth - 
      1.5 * unemployment_rate + 
      0.5 * fiscal_spending + 
      ifelse(country_size == "Large", 10, 0) + 
      rnorm(200, 0, 12)
  )

# Economics analysis
econ_result <- jsjplot(
  data = economics_data,
  analysis_type = "coefficient_plot",
  dependent_var = "economic_satisfaction",
  independent_vars = c("gdp_growth", "unemployment_rate", "fiscal_spending", "country_size"),
  model_type = "lm",
  colors = "metro",
  title = "Economic Determinants of Satisfaction"
)

Clinical Research Example

# Create clinical trial dataset
clinical_data <- data.frame(
  patient_id = 1:300,
  # Baseline characteristics
  age = round(rnorm(300, 55, 15)),
  gender = factor(sample(c("Male", "Female"), 300, replace = TRUE)),
  baseline_severity = rnorm(300, 50, 15),
  comorbidities = rpois(300, 1.5),
  # Treatment
  treatment_arm = factor(sample(c("Placebo", "Low_Dose", "High_Dose"), 
                               300, replace = TRUE)),
  # Outcomes
  treatment_response = rbinom(300, 1, 0.4),
  side_effects = rpois(300, 0.8),
  quality_of_life = rnorm(300, 70, 20)
) %>%
  mutate(
    treatment_response = rbinom(300, 1, plogis(-1.5 + 
      ifelse(treatment_arm == "Low_Dose", 0.8, 0) + 
      ifelse(treatment_arm == "High_Dose", 1.5, 0) - 
      0.01 * baseline_severity)),
    
    quality_of_life = quality_of_life + 
      ifelse(treatment_response == 1, 15, 0) - 
      0.2 * age - 
      3 * comorbidities + 
      rnorm(300, 0, 12)
  )

# Clinical analysis - treatment response
clinical_response <- jsjplot(
  data = clinical_data,
  analysis_type = "coefficient_plot",
  dependent_var = "treatment_response",
  independent_vars = c("treatment_arm", "age", "baseline_severity", "gender"),
  model_type = "logistic",
  theme_style = "minimal",
  title = "Predictors of Treatment Response"
)

# Quality of life analysis
clinical_qol <- jsjplot(
  data = clinical_data,
  analysis_type = "coefficient_plot",
  dependent_var = "quality_of_life",
  independent_vars = c("treatment_response", "age", "comorbidities"),
  model_type = "lm",
  title = "Factors Affecting Quality of Life"
)

Error Handling and Troubleshooting

Missing Data

# Create data with missing values
missing_data <- research_data
missing_data$life_satisfaction[sample(1:300, 30)] <- NA
missing_data$age[sample(1:300, 20)] <- NA

# Analysis with missing data
missing_result <- jsjplot(
  data = missing_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "gender"),
  model_type = "lm"
)

Small Sample Sizes

# Small dataset
small_data <- research_data[1:30, ]

# Analysis with small sample
small_result <- jsjplot(
  data = small_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education"),
  model_type = "lm"
)

Edge Cases

# Constant variable (no variation)
edge_data <- research_data
edge_data$constant_var <- 5

# Perfect correlation
edge_data$age_copy <- edge_data$age

# Analysis with edge cases
edge_result <- jsjplot(
  data = edge_data,
  analysis_type = "coefficient_plot",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "constant_var"),
  model_type = "lm"
)

Performance and Optimization

Caching Benefits

# Large dataset for performance testing
large_data <- do.call(rbind, replicate(3, research_data, simplify = FALSE))
large_data$id <- 1:nrow(large_data)

# First run (will be slower)
system.time({
  perf_result1 <- jsjplot(
    data = large_data,
    analysis_type = "coefficient_plot",
    dependent_var = "life_satisfaction",
    independent_vars = c("age", "years_education", "gender", "marital_status"),
    model_type = "lm"
  )
})

# Second run with same data/options (should be faster due to caching)
system.time({
  perf_result2 <- jsjplot(
    data = large_data,
    analysis_type = "coefficient_plot",
    dependent_var = "life_satisfaction",
    independent_vars = c("age", "years_education", "gender", "marital_status"),
    model_type = "lm"
  )
})

Best Practices

1. Model Selection Guidelines

# Create guidance table
model_guide <- data.frame(
  Outcome_Type = c(
    "Continuous (normal)",
    "Binary (0/1)",
    "Count (0,1,2,...)",
    "Ordinal",
    "Time-to-event"
  ),
  Recommended_Model = c(
    "lm (Linear Model)",
    "logistic (Logistic Regression)",
    "poisson (Poisson Regression)",
    "logistic with ordinal package",
    "Survival models (not implemented)"
  ),
  jsjplot_Setting = c(
    "model_type = 'lm'",
    "model_type = 'logistic'",
    "model_type = 'poisson'",
    "model_type = 'logistic'",
    "Not available"
  ),
  Example_Use = c(
    "Life satisfaction, test scores",
    "Employment status, treatment response",
    "Number of events, visits",
    "Likert scales, rankings",
    "Time to treatment response"
  )
)

print(model_guide)

2. Visualization Guidelines

# Best practices for different analysis types
viz_guide <- data.frame(
  Analysis_Type = c(
    "coefficient_plot",
    "regression_table",
    "interaction_plot",
    "marginal_effects",
    "frequency_table",
    "correlation_matrix",
    "pca_plot"
  ),
  Best_For = c(
    "Comparing effect sizes across predictors",
    "Publication-ready regression results",
    "Visualizing interaction effects",
    "Showing predicted values and effects",
    "Descriptive analysis of categories",
    "Exploring variable relationships",
    "Dimensionality reduction visualization"
  ),
  Recommended_Options = c(
    "sort_estimates=TRUE, remove_intercept=TRUE",
    "show_p_values=TRUE, confidence_level=0.95",
    "Clear labeling of interaction variables",
    "plot_type='eff' for effects",
    "Limit to important categorical variables",
    "Use with numeric variables only",
    "Good for 3+ numeric variables"
  )
)

print(viz_guide)

3. Statistical Interpretation

# Effect size interpretation guidelines
effect_guide <- data.frame(
  Effect_Size = c("Small", "Medium", "Large"),
  Cohen_d = c("0.2", "0.5", "0.8"),
  R_squared = c("0.01", "0.09", "0.25"),
  Interpretation = c(
    "Subtle but potentially important",
    "Moderate practical significance",
    "Large practical significance"
  )
)

print(effect_guide)

Reporting Results

APA Style Reporting

# Example of APA-style analysis
apa_result <- jsjplot(
  data = research_data,
  analysis_type = "regression_table",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "marital_status"),
  model_type = "lm",
  theme_style = "apa",
  confidence_level = 0.95,
  show_p_values = TRUE,
  standardized = TRUE
)

Publication-Ready Tables

# High-quality table for publication
pub_table <- jsjplot(
  data = research_data,
  analysis_type = "regression_table",
  dependent_var = "life_satisfaction",
  independent_vars = c("age", "years_education", "gender", "marital_status", "income_bracket"),
  model_type = "lm",
  html_output = TRUE,
  show_p_values = TRUE,
  standardized = FALSE,
  confidence_level = 0.95
)

Summary

The jsjplot function provides a comprehensive solution for social science statistical visualization and analysis. Key advantages include:

Core Capabilities

  • Multiple Analysis Types: Seven different analysis types covering most social science research needs
  • Model Flexibility: Support for linear, logistic, Poisson, and generalized linear models
  • Publication Quality: High-quality plots and tables ready for publication
  • Statistical Rigor: Confidence intervals, significance tests, and model diagnostics

Performance Features

  • Intelligent Caching: Automatic caching of models and results for faster repeated analyses
  • Error Handling: Robust error handling for missing data and edge cases
  • Memory Efficiency: Optimized for large datasets with smart data preparation
  • Validation: Comprehensive input validation and informative error messages

Customization Options

  • Visual Themes: Multiple themes including APA style for publications
  • Color Schemes: Color-blind friendly and aesthetically pleasing palettes
  • Plot Customization: Extensive control over plot elements and styling
  • Output Formats: HTML tables and high-resolution plots

Use Cases

  • Academic Research: Psychology, sociology, political science, economics
  • Clinical Research: Treatment effects, patient outcomes, clinical trials
  • Business Analytics: Customer satisfaction, employee surveys, market research
  • Policy Analysis: Public policy evaluation, social program assessment

Next Steps

  • Explore the ClinicoPath package documentation for more analysis functions
  • Try different analysis types with your own data
  • Experiment with customization options for publication-ready outputs
  • Consider the sjPlot package documentation for advanced features