【问题标题】:How can I solve the error: "The R package "lme4" is not installed when using the pymer4 library within python?如何解决错误:“在 python 中使用 pymer4 库时未安装 R 包“lme4”?
【发布时间】:2021-11-11 00:20:18
【问题描述】:

我正在尝试遵循此处详述的示例:Mixed effects logistic regression,但我在该行收到“PackageNotInstalledError: The R package "lme4" is not installed” results = model.fit()

数据集可以在这里下载:https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv

我的代码是:

import os 
import pandas as pd
import statsmodels.genmod.bayes_mixed_glm as smgb
from pymer4.models import Lmer

titanic = pd.read_csv(os.path.join(os.getcwd(), 'titanic.csv'))

model = Lmer("Survived  ~ Age  + (1|Pclass)",
             data=titanic, family = 'binomial')

results = model.fit())

print (results)

Lmer 函数有效,只是当我尝试拟合模型时出现错误。我曾假设所需的软件包已包含在 pymer4.xml 中。任何有关如何安装此软件包的想法将不胜感激。

【问题讨论】:

  • 你是如何开始安装pymer4的?
  • 我在 conda 环境中使用了“pip install pymer4”
  • 您是否阅读了Installation,特别是作者明确建议不要使用pip 安装的部分,以及他们提到如何与库本身一起安装必要的 R 包的部分(如果出现您上面提到的错误该怎么办)?
  • 我修复了这个问题:conda install -c ejolly -c defaults -c conda-forge pymer4
  • @esqew 我建议你以后不要勉强提供帮助。但是,无论如何,感谢您在最初的评论中为我指明了正确的方向。

标签: python logistic-regression statsmodels mixed-models


【解决方案1】:

我通过使用以下方法重新安装 pymer4 解决了这个问题:

conda install -c ejolly -c defaults -c conda-forge pymer4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多