You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python中用REML实现嵌套式Variant Components Analysis(VCA)

问题:Python中不使用rpy2实现REML嵌套变异分量分析(VCA)

我尝试用以下Python代码通过REML进行变异分量分析(Variant Components Analysis, VCA):

import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols
data = {'Part':[1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3],
        'Employee':[1,1,1,2,2,2,3,3,3,1,1,1,2,2,2,3,3,3,1,1,1,2,2,2,3,3,3],
        'Measurement':[103.3, 103.1, 103.1, 103.3, 102.9, 103.6, 103.2, 103.6, 103.1, 104.5, 104.8, 103.9, 104.5, 104, 103.8, 103.8, 103.6, 104, 104, 103.6, 103.5, 103.9, 104.1, 104.5, 104.3, 103.9, 103.8]} 
df = pd.DataFrame(data)
lm = ols('Measurement ~ C(Part) + C(Part):(Employee)', data=df).fit()
table = sm.stats.anova_lm(lm, typ=2)
table['Percentage of Total Variance'] = (table['sum_sq'] / table['sum_sq'].sum()) * 100

但通过JMP的指定步骤(粘贴表格、选择Analyze> Quality and Process > Variability / Attribute Gauge Chart,设置REML分析等)以及R的VCA包代码:

library('VCA')
library('dplyr')
df <- read.csv('simpler.csv', sep=';')
df$Part <- as.factor(df$Part)
df$Employee <- as.factor(df$Employee)
fitREML <- remlVCA(form=Measurement~Part+Part/Employee, Data = df)

得到了一致的嵌套变异分量结果,Python代码的输出却无法匹配。请问是否可以不使用rpy2在Python中实现符合要求的分析?

需求细节

  • 需采用REML分析
  • 需进行嵌套分析
  • 曾尝试statsmodels混合模型,但分组语法不清晰

内容的提问来源于stack exchange,提问作者Ranieri Bubans

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 09:02:19