has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
3.89k stars 209 forks source link

What's the syntax for geom_smooth with binomial family? #769

Closed bhvieira closed 3 months ago

bhvieira commented 3 months ago

This does not work:

# example
x = np.linspace(0, 1, 100)
y = np.random.binomial(1, 0.5, 100)
dat = pd.DataFrame({"x": x, "y": y})

ggplot(dat, aes(x="x", y="y")) + geom_point() + geom_smooth(method="glm", method_args={"family": "binomial"})

Returns AttributeError: 'str' object has no attribute 'link'

The analogue in R works like:

library(ggplot2)

x <- seq(0, 1, length=100)
y <- rbinom(100, 1, 0.5)
dat <- data.frame(x=x, y=y)
ggplot(dat, aes(x=x, y=y)) + geom_point() + geom_smooth(method="glm", method.args=list(family="binomial"))

Info:

bhvieira commented 3 months ago

I see I'm in a fairly old version, so perhaps this has been fixed. I can test later, so sorry in advance if that is the case.

bhvieira commented 3 months ago

Tested again after updating, still occurs


Info: