科研 Skill
回归模型诊断检验
regression-diagnostics
Checks regression assumptions (linearity, heteroskedasticity, normality), VIF, and influential-outlier diagnostics. Use when validating a fitted regression model before reporting.
SKILL.md
<skill_content>
The consequences of ignoring diagnostics are severe: heteroskedasticity can inflate Type I error rates from 5% to 40%, influential outliers can reverse coefficient signs, and multicollinearity can make estimates unstable. This skill enforces rigorous diagnostic practices that protect against these failures.
FUNDAMENTAL TRUTH: Statistical software will happily compute invalid estimates. It's YOUR responsibility to verify assumptions hold. No diagnostic → no inference. </core_principle>
<mandatory_requirements>
</mandatory_requirements>
<thinking_process> When running regression diagnostics:
- Generate diagnostic plots FIRST (visual inspection reveals patterns)
- Run formal tests for each assumption
- Compute influence measures for all observations
- Check multicollinearity among predictors
- Document ALL violations found
- Provide specific remediation for each violation
- Re-run diagnostics after any remediation
- Report sensitivity to different specifications </thinking_process>
<implementation_pattern>
<code_template>
# CRITICAL: Complete regression diagnostics template
@app.cell
def complete_regression_diagnostics(model, df, cluster_var=None):
"""
Comprehensive diagnostics are mandatory for valid inference.
Every assumption violation has specific consequences and remediation.
This function enforces systematic checking and clear reporting.
"""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy import stats
from statsmodels.stats.diagnostic import het_breuschpagan, het_white
from statsmodels.stats.outliers_influence import variance_inflation_factor, OLSInfluence
import os
print("=" * 70)
print("COMPREHENSIVE REGRESSION DIAGNOSTICS")
print("=" * 70)
# Extract residuals and fitted values
fitted = model.fittedvalues
residuals = model.resid
standardized_resid = residuals / residuals.std()
# 1. DIAGNOSTIC PLOTS (mandatory visualization)
fig, axes = plt.subplots(2, 2, figsize=(14, 12))
# Residuals vs Fitted (linearity + homoskedasticity)
axes[0, 0].scatter(fitted, residuals, alpha=0.5, s=30)
axes[0, 0].axhline(0, color='red', linestyle='--', linewidth=1.5)
# Add loess smoother to detect patterns
from scipy.interpolate import interp1d
sorted_idx = np.argsort(fitted)
window = max(10, len(fitted) // 20)
smoothed = pd.Series(residuals[sorted_idx]).rolling(window, center=True).mean()
axes[0, 0].plot(fitted[sorted_idx], smoothed, 'g-', linewidth=2, label='Loess smoother')
axes[0, 0].set_xlabel("Fitted Values", fontsize=11)
axes[0, 0].set_ylabel("Residuals", fontsize=11)
axes[0, 0].set_title("Residuals vs Fitted\n(Check: Random scatter around zero)", fontsize=12)
axes[0, 0].grid(True, alpha=0.3)
axes[0, 0].legend()
# Q-Q Plot (normality)
stats.probplot(residuals, dist="norm", plot=axes[0, 1])
axes[0, 1].set_title("Normal Q-Q Plot\n(Check: Points follow diagonal)", fontsize=12)
axes[0, 1].grid(True, alpha=0.3)
# Scale-Location (homoskedasticity)
sqrt_abs_resid = np.sqrt(np.abs(standardized_resid))
axes[1, 0].scatter(fitted, sqrt_abs_resid, alpha=0.5, s=30)
# Add trend line
z = np.polyfit(fitted, sqrt_abs_resid, 1)
p = np.poly1d(z)
axes[1, 0].plot(fitted, p(fitted), "r-", linewidth=2, label=f'Trend: slope={z[0]:.3f}')
axes[1, 0].set_xlabel("Fitted Values", fontsize=11)
axes[1, 0].set_ylabel("√|Standardized Residuals|", fontsize=11)
axes[1, 0].set_title("Scale-Location\n(Check: Horizontal band, no trend)", fontsize=12)
axes[1, 0].grid(True, alpha=0.3)
axes[1, 0].legend()
# Residuals vs Leverage (influence)
influence = OLSInfluence(model)
leverage = influence.hat_matrix_diag
cooks_d = influence.cooks_distance[0]
axes[1, 1].scatter(leverage, standardized_resid, alpha=0.5, s=30)
axes[1, 1].axhline(0, color='red', linestyle='--', linewidth=1.5)
# Mark influential points
n = len(residuals)
threshold = 4 / n
influential_mask = cooks_d > threshold
if influential_mask.any():
axes[1, 1].scatter(leverage[influential_mask],
standardized_resid[influential_mask],
color='red', s=100, alpha=0.7,
label=f'Influential (Cook\'s D > {threshold:.3f})')
# Add contour lines for Cook's distance
x_leverage = np.linspace(0, max(leverage) * 1.1, 50)
for cooks_level in [0.5, 1.0]:
y_resid = np.sqrt(cooks_level * n / (x_leverage * (1 - x_leverage)))
axes[1, 1].plot(x_leverage, y_resid, '--', color='gray', alpha=0.5)
axes[1, 1].plot(x_leverage, -y_resid, '--', color='gray', alpha=0.5)
axes[1, 1].set_xlabel("Leverage", fontsize=11)
axes[1, 1].set_ylabel("Standardized Residuals", fontsize=11)
axes[1, 1].set_title("Residuals vs Leverage\n(Check: No influential outliers)", fontsize=12)
axes[1, 1].grid(True, alpha=0.3)
axes[1, 1].legend()
plt.suptitle("Regression Diagnostic Plots - ALL FOUR REQUIRED", fontsize=14, y=1.02)
plt.tight_layout()
os.makedirs("./images", exist_ok=True)
plt.savefig("./images/regression_diagnostics_complete.png", dpi=144, bbox_inches="tight")
# Save figure reference for inline display
diagnostic_fig = plt.gcf()
# 2. HETEROSKEDASTICITY TESTS (mandatory formal testing)
print("\n" + "=" * 70)
print("HETEROSKEDASTICITY TESTS")
print("-" * 70)
bp_stat, bp_pval, _, _ = het_breuschpagan(residuals, model.model.exog)
white_stat, white_pval, _, _ = het_white(residuals, model.model.exog)
print(f"Breusch-Pagan Test:")
print(f" Statistic: {bp_stat:.4f}, p-value: {bp_pval:.4f}")
print(f" Interpretation: {'VIOLATION - Heteroskedasticity detected' if bp_pval < 0.05 else 'No violation detected'}")
print(f"\nWhite Test:")
print(f" Statistic: {white_stat:.4f}, p-value: {white_pval:.4f}")
print(f" Interpretation: {'VIOLATION - Heteroskedasticity detected' if white_pval < 0.05 else 'No violation detected'}")
if bp_pval < 0.05 or white_pval < 0.05:
print("\nWARNING: REQUIRED ACTION:")
print(" 1. Use robust standard errors: model.get_robustcov_results(cov_type='HC3')")
if cluster_var:
print(f" 2. Or cluster-robust SE: cov_type='cluster', cov_kwds={{'groups': df['{cluster_var}']}}")
print(" 3. Consider variance-stabilizing transformation (log, sqrt)")
print(" 4. Check for omitted variables or incorrect functional form")
# 3. MULTICOLLINEARITY (VIF mandatory for all predictors)
print("\n" + "=" * 70)
print("MULTICOLLINEARITY ASSESSMENT (VIF)")
print("-" * 70)
X = model.model.exog
vif_data = []
for i in range(X.shape[1]):
if model.model.exog_names[i] == 'const':
continue # Skip constant term
vif = variance_inflation_factor(X, i)
vif_data.append({
'Variable': model.model.exog_names[i],
'VIF': vif,
'Status': 'SEVERE' if vif > 10 else 'High' if vif > 5 else 'OK'
})
vif_df = pd.DataFrame(vif_data).sort_values('VIF', ascending=False)
print(vif_df.to_string(index=False))
severe_collinear = vif_df[vif_df['VIF'] > 10]
high_collinear = vif_df[vif_df['VIF'] > 5]
if len(severe_collinear) > 0:
print("\nWARNING: SEVERE MULTICOLLINEARITY DETECTED:")
for _, row in severe_collinear.iterrows():
print(f" {row['Variable']}: VIF = {row['VIF']:.2f}")
print("\nREQUIRED ACTIONS:")
print(" 1. Remove one of the correlated variables")
print(" 2. Combine into index/principal component")
print(" 3. Use ridge regression for regularization")
elif len(high_collinear) > 0:
print("\nWARNING: Moderate multicollinearity detected. Monitor but may be acceptable.")
# 4. INFLUENCE DIAGNOSTICS (identify problematic observations)
print("\n" + "=" * 70)
print("INFLUENTIAL OBSERVATIONS")
print("-" * 70)
n_influential = influential_mask.sum()
high_leverage = leverage > (2 * (X.shape[1]) / n)
n_high_leverage = high_leverage.sum()
print(f"Cook's Distance threshold (4/n): {threshold:.4f}")
print(f"Influential observations: {n_influential} ({100*n_influential/n:.1f}% of data)")
print(f"High leverage observations: {n_high_leverage} ({100*n_high_leverage/n:.1f}% of data)")
if n_influential > 0:
influential_idx = np.where(influential_mask)[0]
print(f"\nInfluential observation indices: {influential_idx[:10]}") # Show first 10
print("\nWARNING: REQUIRED ACTIONS:")
print(" 1. Investigate these observations for data errors")
print(" 2. Check if they represent valid but unusual cases")
print(" 3. Report results with AND without influential points")
print(" 4. Consider robust regression if many influential points")
# 5. NORMALITY TESTS (for valid inference)
print("\n" + "=" * 70)
print("NORMALITY OF RESIDUALS")
print("-" * 70)
shapiro_stat, shapiro_pval = stats.shapiro(residuals[:5000]) # Shapiro-Wilk (limit 5000)
jb_stat, jb_pval = stats.jarque_bera(residuals)
print(f"Shapiro-Wilk Test: p-value = {shapiro_pval:.4f}")
print(f"Jarque-Bera Test: p-value = {jb_pval:.4f}")
if shapiro_pval < 0.05 or jb_pval < 0.05:
print("\nWARNING: Non-normality detected in residuals")
print("NOTES:")
print(" - With n > 30, CLT often ensures valid inference despite non-normality")
print(" - For small samples, consider bootstrap or transformation")
print(" - Check for outliers causing non-normality")
# 6. SUMMARY RECOMMENDATIONS
print("\n" + "=" * 70)
print("DIAGNOSTIC SUMMARY & REQUIRED ACTIONS")
print("=" * 70)
violations = []
if bp_pval < 0.05 or white_pval < 0.05:
violations.append("Heteroskedasticity → Use robust/clustered SE")
if len(severe_collinear) > 0:
violations.append("Severe multicollinearity → Remove/combine variables")
if n_influential > 0:
violations.append("Influential observations → Report sensitivity")
if (shapiro_pval < 0.05 or jb_pval < 0.05) and n < 30:
violations.append("Non-normal residuals (small sample) → Bootstrap/transform")
if violations:
print("WARNING: VIOLATIONS REQUIRING ACTION:")
for i, v in enumerate(violations, 1):
print(f" {i}. {v}")
else:
print("SUCCESS: No major violations detected. Standard inference is valid.")
print("\nDiagnostic plots saved to: ./images/regression_diagnostics_complete.png")
# Return figure for inline display along with diagnostic results
return vif_df, influential_mask, cooks_d, diagnostic_fig,
</code_template>
</implementation_pattern>
import pandas as pd
import numpy as np
import statsmodels.formula.api as smf
# Simulated clean data for demonstration
np.random.seed(42)
n = 500
df = pd.DataFrame({
'x1': np.random.normal(0, 1, n),
'x2': np.random.normal(0, 1, n),
'x3': np.random.normal(0, 1, n),
})
# Well-specified model with homoskedastic errors
df['y'] = 2 + 3*df['x1'] - 1.5*df['x2'] + 0.8*df['x3'] + np.random.normal(0, 2, n)
# Estimate model
model = smf.ols('y ~ x1 + x2 + x3', data=df).fit()
print("MODEL SUMMARY")
print("=" * 70)
print(model.summary())
# Run complete diagnostics
vif_df, influential, cooks = complete_regression_diagnostics(model, df)
# INTERPRETATION
print("\n" + "=" * 70)
print("INTERPRETATION FOR CLEAN MODEL")
print("=" * 70)
print("""
This is an example of a well-behaved regression:
1. Residuals vs Fitted: Random scatter around zero [OK]
→ Linear specification is appropriate
2. Q-Q Plot: Points follow diagonal line [OK]
→ Residuals are approximately normal
3. Scale-Location: Horizontal band, no trend [OK]
→ Variance is constant (homoskedastic)
4. Residuals vs Leverage: No points outside Cook's distance contours [OK]
→ No influential outliers distorting results
5. VIF values all < 5 [OK]
→ No problematic multicollinearity
6. Heteroskedasticity tests p > 0.05 [OK]
→ Can use standard errors as computed
CONCLUSION: Standard inference is valid. Report results as-is.
""")
return model, vif_df,
</code>
<lesson>
Even with "clean" data, running diagnostics is non-negotiable. This example shows what good diagnostics look like—use this as a reference for comparison.
</lesson>
</example>
<example context="heteroskedastic_regression" difficulty="intermediate">
<description>Regression with heteroskedasticity requiring robust standard errors</description>
<code>
```python
@app.cell
def diagnose_heteroskedastic_model():
#Heteroskedasticity is common in cross-sectional data.
# We detect it, apply robust SE, and show the difference in inference.
import pandas as pd
import numpy as np
import statsmodels.formula.api as smf
np.random.seed(123)
n = 500
# Generate data with heteroskedastic errors
df = pd.DataFrame({
'income': np.random.lognormal(10, 1, n), # Log-normal income
'education': np.random.normal(12, 3, n),
'experience': np.random.uniform(0, 40, n),
})
# Error variance increases with income (heteroskedasticity)
error_sd = 0.1 * df['income'] # Variance proportional to income
df['consumption'] = (
1000 +
0.7 * df['income'] +
50 * df['education'] +
20 * df['experience'] +
np.random.normal(0, error_sd)
)
# Naive model (ignoring heteroskedasticity)
model_naive = smf.ols('consumption ~ income + education + experience', data=df).fit()
print("NAIVE MODEL (Standard Errors)")
print("=" * 70)
print(model_naive.summary())
# Run diagnostics - will detect heteroskedasticity
vif_df, influential, cooks = complete_regression_diagnostics(model_naive, df)
# CORRECTED MODEL with robust standard errors
print("\n" + "=" * 70)
print("CORRECTED MODEL (HC3 Robust Standard Errors)")
print("=" * 70)
# HC3 is preferred for finite samples (MacKinnon & White 1985)
model_robust = model_naive.get_robustcov_results(cov_type='HC3')
print(model_robust.summary())
# Compare standard errors
comparison = pd.DataFrame({
'Variable': model_naive.params.index,
'Coef': model_naive.params.values,
'SE (Naive)': model_naive.bse.values,
'SE (Robust)': model_robust.bse.values,
'SE Ratio': model_robust.bse.values / model_naive.bse.values,
'p-val (Naive)': model_naive.pvalues.values,
'p-val (Robust)': model_robust.pvalues.values,
})
print("\n" + "=" * 70)
print("STANDARD ERROR COMPARISON")
print("=" * 70)
print(comparison.to_string(index=False))
print("\n" + "=" * 70)
print("KEY INSIGHTS")
print("=" * 70)
print("""
1. Heteroskedasticity detected (p < 0.001) in both tests
2. Robust SEs are larger for variables correlated with variance
3. Some coefficients lose significance with correct SEs
4. Ignoring heteroskedasticity gave false precision
LESSON: Always test for heteroskedasticity. When detected,
robust standard errors are MANDATORY for valid inference.
""")
return model_robust, comparison,
import pandas as pd
import numpy as np
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
import os
np.random.seed(789)
n = 200
# Generate mostly normal data
df = pd.DataFrame({
'x': np.random.normal(50, 10, n),
'z': np.random.normal(0, 1, n),
})
df['y'] = 10 + 2*df['x'] + 5*df['z'] + np.random.normal(0, 10, n)
# Add influential outliers
outliers = pd.DataFrame({
'x': [100, 105, 110], # High leverage points
'z': [0, 0, 0],
'y': [50, 45, 40], # Don't follow pattern
})
df = pd.concat([df, outliers], ignore_index=True)
# Full model (with outliers)
model_full = smf.ols('y ~ x + z', data=df).fit()
print("FULL MODEL (Including Outliers)")
print("=" * 70)
print(model_full.summary())
# Run diagnostics - will identify influential points
vif_df, influential_mask, cooks_d = complete_regression_diagnostics(model_full, df)
# Model without influential observations
print("\n" + "=" * 70)
print("ROBUST MODEL (Excluding Influential Points)")
print("=" * 70)
df_clean = df[~influential_mask].copy()
model_robust = smf.ols('y ~ x + z', data=df_clean).fit()
print(model_robust.summary())
# Sensitivity comparison
print("\n" + "=" * 70)
print("SENSITIVITY ANALYSIS")
print("=" * 70)
comparison = pd.DataFrame({
'Model': ['With Outliers', 'Without Outliers'],
'n': [len(df), len(df_clean)],
'β_x': [model_full.params['x'], model_robust.params['x']],
'SE_x': [model_full.bse['x'], model_robust.bse['x']],
'p_x': [model_full.pvalues['x'], model_robust.pvalues['x']],
'R²': [model_full.rsquared, model_robust.rsquared],
})
print(comparison.to_string(index=False))
# Visualize influence
fig, axes = plt.subplots(1, 2, figsize=(14, 6))
# Plot 1: Data with regression lines
axes[0].scatter(df[~influential_mask]['x'],
df[~influential_mask]['y'],
alpha=0.5, label='Normal observations')
axes[0].scatter(df[influential_mask]['x'],
df[influential_mask]['y'],
color='red', s=100, label='Influential outliers')
x_range = np.linspace(df['x'].min(), df['x'].max(), 100)
axes[0].plot(x_range,
model_full.params['const'] + model_full.params['x']*x_range,
'r--', label='With outliers', linewidth=2)
axes[0].plot(x_range,
model_robust.params['const'] + model_robust.params['x']*x_range,
'g-', label='Without outliers', linewidth=2)
axes[0].set_xlabel("X")
axes[0].set_ylabel("Y")
axes[0].set_title("Outlier Impact on Regression Line")
axes[0].legend()
axes[0].grid(True, alpha=0.3)
# Plot 2: Cook's distance
axes[1].stem(range(len(cooks_d)), cooks_d, markerfmt=",", basefmt=" ")
axes[1].axhline(4/len(df), color='red', linestyle='--',
label=f'Threshold = {4/len(df):.3f}')
axes[1].set_xlabel("Observation Index")
axes[1].set_ylabel("Cook's Distance")
axes[1].set_title("Influence Measure (Cook's D)")
axes[1].legend()
axes[1].grid(True, alpha=0.3)
plt.tight_layout()
os.makedirs("./images", exist_ok=True)
plt.savefig("./images/outlier_influence_analysis.png", dpi=144, bbox_inches="tight")
# Save figure reference for inline display
influence_fig = plt.gcf()
print("\n" + "=" * 70)
print("CRITICAL FINDINGS")
print("=" * 70)
print(f"""
1. {influential_mask.sum()} influential observations detected
2. Coefficient on x changes by {abs(model_full.params['x'] - model_robust.params['x']):.3f}
3. R² drops from {model_full.rsquared:.3f} to {model_robust.rsquared:.3f}
4. Statistical significance {'changes' if (model_full.pvalues['x'] < 0.05) != (model_robust.pvalues['x'] < 0.05) else 'unchanged'}
REQUIRED REPORTING:
- Present BOTH models (with and without influential points)
- Investigate influential observations for data quality
- If outliers are valid, consider robust regression methods
- State clearly which results are sensitive to outliers
This demonstrates why influence diagnostics are MANDATORY.
""")
# Return figure for inline display along with models
return model_full, model_robust, influential_mask, influence_fig,
</code>
<power_user_tip>
When influential observations are detected:
1. NEVER simply delete them without investigation
2. Check if they're data errors or valid extreme cases
3. Report results both with AND without
4. Consider robust methods (M-estimation, quantile regression)
5. Document which conclusions are robust to their inclusion
</power_user_tip>
</example>
</examples>
<common_mistakes>
<mistake severity="critical">
<what>Running regression without any diagnostics</what>
<consequence>Invalid p-values, wrong confidence intervals, false discoveries</consequence>
<prevention>ALWAYS run complete_regression_diagnostics() after EVERY regression</prevention>
</mistake>
<mistake severity="critical">
<what>Ignoring heteroskedasticity in cross-sectional data</what>
<consequence>Type I error rates up to 40% instead of 5%</consequence>
<prevention>Always test with Breusch-Pagan/White, use robust SE if detected</prevention>
</mistake>
<mistake severity="critical">
<what>Not checking for influential observations</what>
<consequence>Results driven by 1-2 outliers rather than general pattern</consequence>
<prevention>Compute Cook's distance, report sensitivity to outlier exclusion</prevention>
</mistake>
<mistake severity="high">
<what>Ignoring severe multicollinearity (VIF > 10)</what>
<consequence>Unstable estimates, coefficients flip signs with minor changes</consequence>
<prevention>Check VIF for all variables, remove/combine if VIF > 10</prevention>
</mistake>
<mistake severity="high">
<what>Using classical SE when robust SE required</what>
<consequence>Overstated precision, false statistical significance</consequence>
<prevention>Default to HC3 robust SE when heteroskedasticity detected</prevention>
</mistake>
<mistake severity="medium">
<what>Over-interpreting normality tests with large samples</what>
<consequence>Unnecessary transformations when CLT ensures valid inference</consequence>
<prevention>With n > 30, normality violations rarely affect inference materially</prevention>
</mistake>
</common_mistakes>
<interpretation_guide>
<reading_diagnostic_plots>
**Residuals vs Fitted**:
- GOOD: Random scatter around horizontal line at zero
- BAD: Patterns (curves, fans, clusters) indicate misspecification
**Q-Q Plot**:
- GOOD: Points follow diagonal reference line
- BAD: S-shapes indicate skewness, heavy tails indicate outliers
**Scale-Location**:
- GOOD: Horizontal band with no trend
- BAD: Increasing/decreasing spread indicates heteroskedasticity
**Residuals vs Leverage**:
- GOOD: Points within Cook's distance contours
- BAD: Points in top-right or bottom-right corners are influential
</reading_diagnostic_plots>
<decision_tree>
Heteroskedasticity detected?
→ YES: Use HC3 robust SE or cluster-robust if panel data
→ NO: Classical SE are valid
Multicollinearity detected (VIF > 10)?
→ YES: Must drop variables or use regularization
→ NO but VIF > 5: Monitor, may be acceptable
Influential outliers detected?
→ YES: Report results with AND without
→ NO: Single model sufficient
Non-normal residuals?
→ n > 30: Usually OK (CLT)
→ n < 30: Consider bootstrap or transformation
</decision_tree>
<honest_limitations>
- Diagnostics can't detect all problems (e.g., omitted variables)
- Some violations may not matter for specific research questions
- Trade-offs exist (robust SE have lower power)
- Perfect models don't exist—document deviations honestly
</honest_limitations>
</interpretation_guide>
<references>
<paper>Belsley, D.A., Kuh, E., & Welsch, R.E. (1980). Regression Diagnostics: Identifying Influential Data and Sources of Collinearity. The foundational text on regression diagnostics.</paper>
<paper>Cook, R.D. & Weisberg, S. (1982). Residuals and Influence in Regression. Introduces Cook's distance for influence detection.</paper>
<paper>MacKinnon, J.G. & White, H. (1985). "Some heteroskedasticity-consistent covariance matrix estimators with improved finite sample properties." HC3 robust standard errors.</paper>
<paper>Kutner, M.H., Nachtsheim, C.J., & Neter, J. (2004). Applied Linear Regression Models. Comprehensive treatment of multicollinearity and VIF.</paper>
<paper>Long, J.S. & Ervin, L.H. (2000). "Using heteroscedasticity consistent standard errors in the linear regression model." Practical guide to robust inference.</paper>
</references>
</skill_content>
示例提示词
帮我检查这个回归模型的异方差、多重共线性和异常值问题。
所属插件
安装该插件会一并获得同领域的 58 个 Skill / MCP。
同插件的其他科研 Skill
- Mesa社会主体建模Builds Mesa agent-based models of opinion dynamics, segregation, social contagion, and network diffusion. Use when simulating emergent social behavior from agent rules.
- Mesa3主体建模引擎Builds agent-based models with the Mesa 3 AgentSet API, cell spaces, and batch_run sweeps for segregation, diffusion, and cooperation. Use for a Mesa 3.x ABM build or debug.
- 观察数据因果推断Estimates causal effects with DiD, IV, RDD, panel fixed effects, and propensity scores via statsmodels, linearmodels, DoWhy, and EconML. Use for observational or quasi-experimental causal estimation.
- 效应量元分析Pools effect sizes across studies with fixed/random-effects models, heterogeneity stats, forest/funnel plots, and publication-bias tests. Use for a systematic review’s quantitative synthesis.
- 缺失数据插补处理Handles missing data by naming the MCAR/MAR/MNAR mechanism, then applying multiple imputation (MICE) or FIML instead of single imputation. Use when a dataset has missing values to treat.
- 多层线性混合模型Fits mixed-effects/multilevel models (random slopes, ICC, GLMMs) for nested or longitudinal data via statsmodels, bambi, or R lme4/brms. Use for grouped data with within- vs between-cluster questions.
- 定性比较分析QCARuns crisp-, multi-value, and fuzzy-set Qualitative Comparative Analysis via R’s QCA package. Use for configurational or necessary/sufficient-condition research.
- 质性编码与主题分析Builds codebooks and computes intercoder reliability (Krippendorff’s alpha, kappa) for thematic or content coding, including human-vs-LLM double coding. Use when coding text or reporting reliability.
- 社会网络结构分析Computes network centrality, community detection, and ERGM inferential models matched to the research question via networkx/igraph. Use for social-network analysis beyond basic visualization.
- 社科研究设计把关Routes a study to its research design (experiment, quasi-experiment, observational, qualitative) and pins the identifying assumption first. Use when choosing a study design.
- 社科推论结论审核Audits inferential claims against the design before publication: unwarranted causal language, p-value/CI misreadings, and multiple-comparison issues. Use when checking a results section.
- 量表测量质量把关Checks that a scale’s reliability, validity, and measurement invariance are established before trusting or comparing it across groups. Use when adopting or reporting a survey instrument.
- 社科研究流程总控Coordinates a study through design, measurement, sampling, analysis, and inference gates with a shared Design Passport. Use for an end-to-end methodology review of a whole study.
- 质性研究可信度把关Gates qualitative trustworthiness before write-up: positionality, credibility, transferability, dependability, confirmability per Lincoln and Guba. Use before writing ethnographic findings.
- 抽样方法与样本量把关Checks that the sampling frame, method, and size match the inference paradigm before data collection. Use when planning recruitment or judging sample generalization.
- 复杂抽样调查分析Analyzes complex-sample survey data with design-based inference: weights, strata, PSUs, and calibration via Python svy or R survey/srvyr. Use for weighted surveys like GSS, ANES, or DHS.
- 文本数据定量分析Analyzes text as social-science data with topic modeling, embeddings, and validated dictionary or classification methods. Use for computational text analysis beyond a keyword count.
- 政策议题框架分析Runs anthropological framing and metaphor analysis on contested-policy documents, producing actor-attributed CSVs for NVivo import. Use for policy-framing or metaphor-analysis coding.
- 跨国比较政治分析Merges QoG, Polity5, and Freedom House data and runs cross-sectional OLS with fixed effects and regime classification. Use for comparative political-institution research.
- 计算社会学方法Covers social-media data collection, bot detection, network homophily, echo-chamber analysis, and conjoint survey experiments. Use for large-scale digital-trace sociology research.
- 冲突事件数据分析Downloads ACLED/UCDP conflict data and runs spatio-temporal clustering, conflict-onset logit panels, and fatality estimation. Use for quantitative armed-conflict research.
- 联合分析调查实验Designs conjoint survey experiments and estimates AMCEs via OLS, marginal means, and respondent-level heterogeneity. Use when designing or analyzing a choice-based conjoint experiment.
- 统计方法教学规范Defines the baseline statistical teaching and reproducibility standards shared across this analysis skill family. Use as the methodology reference other skills in the family build on.
- 人口统计方法分析Computes life tables, Leslie-matrix population projections, Lee-Carter mortality forecasts, and Kitagawa decomposition. Use for formal demographic analysis of mortality or population structure.
常见问题
回归模型诊断检验能做什么?
Checks regression assumptions (linearity, heteroskedasticity, normality), VIF, and influential-outlier diagnostics. Use when validating a fitted regression model before reporting。
如何安装回归模型诊断检验?
在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「回归模型诊断检验」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。
回归模型诊断检验需要哪些权限?
该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。
回归模型诊断检验经过官方审核吗?
是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。