Ran*_*ans 6 python r statsmodels sas-jmp
我有以下 Python 代码,我已经尝试使用 REML 执行 VCA 分析:
\nimport pandas as pd\nimport statsmodels.api as sm\nfrom statsmodels.formula.api import ols\ndata = {\'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],\n \'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],\n \'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]} \ndf = pd.DataFrame(data)\nlm = ols(\'Measurement ~ C(Part) + C(Part):(Employee)\', data=df).fit()\ntable = sm.stats.anova_lm(lm, typ=2)\ntable[\'Percentage of Total Variance\'] = (table[\'sum_sq\'] / table[\'sum_sq\'].sum()) * 100\nRun Code Online (Sandbox Code Playgroud)\n\n当我通过运行以下步骤在 JMP 中运行此 An\xc3\xa1lises 时:
\n
在 R 中可以通过以下代码实现相同的结果:
\nlibrary(\'VCA\')\nlibrary(\'dplyr\')\ndf <- read.csv(\'simpler.csv\', sep=\';\')\ndf$Part <- as.factor(df$Part)\ndf$Employee <- as.factor(df$Employee)\nfitREML <- remlVCA(form=Measurement~Part+Part/Employee, Data = df)\nRun Code Online (Sandbox Code Playgroud)\n\n但是我无法在 Python 中得到相同的结果。有没有一种方法可以在Python中完成而不使用rpy2?
\n细节 1:我正在处理的数据需要 REML 分析。
\n细节2:需要根据R和Python公式进行嵌套分析。
\n细节 3:我已经尝试使用 statsmodels 中的混合模型,但组语法不清楚。