Correlations, factor analysis, and attrition risk with vivaglint for Python

This article covers three statistical analysis functions in vivaglint: measuring how survey questions correlate with each other, identifying latent constructs through factor analysis, and quantifying the relationship between employee sentiment and turnover.

Calculate question correlations

get_correlations() computes pairwise correlations between all survey questions, along with p-values and sample sizes for each pair.

from vivaglint import get_correlations

corr_long = get_correlations(survey, method="pearson")
Parameter Type Default Description
survey GlintSurvey or DataFrame (required) Survey data
method str "pearson" "pearson", "spearman", or "kendall"
format str "long" "long" or "matrix"
use str "pairwise" Missing value handling: "pairwise", "complete", or R-style "pairwise.complete.obs", "complete.obs"
plot bool False If True and format="long", display a correlation heatmap

Matrix format

corr_matrix = get_correlations(survey, format="matrix")

Matrix format returns a square DataFrame with questions as rows and columns. Plotting is ignored in matrix mode.

Extract survey factors

extract_survey_factors() performs exploratory factor analysis (EFA) to identify latent constructs — groups of questions that measure the same underlying dimension.

from vivaglint import extract_survey_factors

factors = extract_survey_factors(survey, n_factors=3, rotation="varimax")
print(factors["factor_summary"])
Parameter Type Default Description
survey GlintSurvey or DataFrame (required) Survey data
n_factors int or None None Number of factors to extract; None runs parallel analysis
rotation str "oblimin" "oblimin", "varimax", "promax", "quartimin", "quartimax", "equamax", or "none"
min_loading float 0.3 Minimum absolute loading to include
fm str "minres" Factoring method: "minres", "ml", "pa", "wls", "gls", or "uls"
plot bool False If True, display a factor loading plot

extract_survey_factors() returns a dict with:

  • factor_summary — DataFrame with question, factor, loading, loading_label, communality, factor_variance_pct
  • fa_object — fitted factor analysis object for advanced use

Note

The Python port mirrors R's rotation options, but rotation="oblimin" and rotation="quartimin" can produce unstable results. Use "varimax" or "promax" when in doubt.

Analyze attrition risk

analyze_attrition() links survey responses to employee termination records to measure whether unfavorable respondents are more likely to leave within specified time windows.

from vivaglint import analyze_attrition

attrition = analyze_attrition(
    survey,
    attrition_file="terminations.csv",
    emp_id_col="Employee ID",
    term_date_col="Termination Date",
    scale_points=5,
    time_periods=[90, 180, 365],
)
Parameter Type Default Description
survey GlintSurvey or DataFrame (required) Survey data; must include Survey Cycle Completion Date
attrition_file str or DataFrame (required) CSV path or DataFrame with employee IDs and termination dates
emp_id_col str None Employee ID column name
term_date_col str None Termination date column name
scale_points int (required) Number of scale points (2-11)
time_periods list[int] [90, 180, 365] Days after survey completion to measure attrition
attribute_cols str or list[str] None Optional attribute columns for segmented results
min_group_size int 5 Minimum employees per attribute group
plot bool False If True, display a grouped bar chart

The output includes one row per question and time period, with:

  • favorable_n, favorable_attrition
  • unfavorable_n, unfavorable_attrition
  • attrition_ratio (unfavorable_attrition / favorable_attrition)

When attribute_cols are supplied, the results prepend those columns and group_size.

Next steps