简体   繁体   English

如何在 rpy2 中使用 gamlss

[英]How to use gamlss with rpy2

I am trying to reproduce this R code in python using rpy2:我正在尝试使用 rpy2 在 python 中重现此R 代码

library(gamlss)
library(gamlss.dist)
library(gamlss.add)

x <- c(37.50,46.79,48.30,46.04,43.40,39.25,38.49,49.51,40.38,36.98,40.00,
       38.49,37.74,47.92,44.53,44.91,44.91,40.00,41.51,47.92,36.98,43.40,
       42.26,41.89,38.87,43.02,39.25,40.38,42.64,36.98,44.15,44.91,43.40,
       49.81,38.87,40.00,52.45,53.13,47.92,52.45,44.91,29.54,27.13,35.60,
       45.34,43.37,54.15,42.77,42.88,44.26,27.14,39.31,24.80,16.62,30.30,
       36.39,28.60,28.53,35.84,31.10,34.55,52.65,48.81,43.42,52.49,38.00,
       38.65,34.54,37.70,38.11,43.05,29.95,32.48,24.63,35.33,41.34)

fit <- fitDist(x, k = 2, type = "realplus", trace = FALSE, try.gamlss = TRUE)

summary(fit)

My attempt is:我的尝试是:

from rpy2.robjects.packages import importr
from rpy2.robjects import numpy2ri
numpy2ri.activate()
utils = importr('utils')
utils.install_packages('gamlss')
gamlss = importr('gamlss')
base = importr('base')
x = np.array([7.50,46.79,48.30,46.04,43.40,39.25,38.49,49.51,40.38,36.98,40.00,
       38.49,37.74,47.92,44.53,44.91,44.91,40.00,41.51,47.92,36.98,43.40,
       42.26,41.89,38.87,43.02,39.25,40.38,42.64,36.98,44.15,44.91,43.40,
       49.81,38.87,40.00,52.45,53.13,47.92,52.45,44.91,29.54,27.13,35.60,
       45.34,43.37,54.15,42.77,42.88,44.26,27.14,39.31,24.80,16.62,30.30,
       36.39,28.60,28.53,35.84,31.10,34.55,52.65,48.81,43.42,52.49,38.00,
       38.65,34.54,37.70,38.11,43.05,29.95,32.48,24.63,35.33,41.34])
base.fitDist(x, k = 2, type = "realplus", trace = FALSE, try.gamlss = TRUE)

This is a syntax error however because of try.gamlss = TRUE .这是一个语法错误,但是由于try.gamlss = TRUE

How should I do this?我该怎么做?

Replace the dot in try.gamlss with an underscore.try.gamlss中的点替换为下划线。

The documentation has explanations: https://rpy2.github.io/doc/v3.3.x/html/robjects_rpackages.html文档有解释: https://rpy2.github.io/doc/v3.3.x/html/robjects_rpackages.ZFC35FDC70D5FC69D269883A822C7A53E

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM