Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_predictions() with categorical variables (factors) in nls model #95

Closed
rungec opened this issue May 3, 2019 · 1 comment
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@rungec
Copy link

rungec commented May 3, 2019

Hi,
When adding nls model predictions to tibble, where nls model includes categorical variable (a factor) add_predictions() seems to assume the tibble is ordered by that factor.
see example below. Works fine for glm models though, so wasn't sure whether to post here or on the nls pages.
Claire

require(tidyverse)

mtcars_tibble <- as_tibble(mtcars) %>% mutate(cyl=as.factor(cyl))

lf <- formula(mpg ~ exp(a+b*wt)| cyl)
mod1 <- nlme::nlsList(lf, data=mtcars_tibble, start=list(a=0,b=0))

mtcars_preds <- mtcars_tibble %>% add_predictions(mod1)

ggplot(mtcars_preds, aes(y=mpg, x=wt, group=cyl))+
  geom_point() +
  geom_line(aes(y=pred), col="red") +
  facet_wrap("cyl")

#adding arrange fixes the problem
mtcars_preds <- mtcars_tibble %>% arrange(cyl) %>% add_predictions(mod1)

ggplot(mtcars_preds, aes(y=mpg, x=wt, group=cyl))+
  geom_point() +
  geom_line(aes(y=pred), col="red") +
  facet_wrap("cyl")
@hadley hadley added the bug an unexpected problem or unintended behavior label Apr 20, 2020
@hadley
Copy link
Member

hadley commented Oct 31, 2023

modelr is now superseded, which means that we'll only perform critical bug fixes needed to keep it on CRAN. Thanks for contributing this idea and my apologies that it took so long to inform you that this package is no longer under development.

@hadley hadley closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants