adding predictions for logistic regression (grouped variable)

HI All this question has been answered in the past here, however this method is not working for me .
I also would like to attain a table with predicted probabilities for new values of my dependent variable (Dose in this case)
the previous post is here :Predictions in logistic regression model by group
when i try the recommended code, i am running into the following error

Error in eval(lhs, parent, parent) : object 'fit_data' not found
I think i have loaded all the packages required . I dont understand why this wouldnt work ?

library(tidyverse)
library(dplyr)
library(broom)
library(purrr)
library(tidyr)
df<-read.csv("IHC_Organ_Dose response_1a.csv")

data.y<-data.frame(dose=0:10)
model<-df %>%
  group_nest(organ) %>% 
  mutate(model = map(data,
                     ~glm(IHC~Dose,
                          data = .x,
                          family = "binomial"))
  ) %>% 
  inner_join(fit_data %>% group_nest(organ), by = "organ") %>% 
  mutate(fitted = map2(model,
                       data.y,
                       ~predict(.x, newdata = .y, type = "response"))) %>% 
  unnest(c("fitted", "data.y")) %>% 
  select(organ, dose, fitted)
**Error in eval(lhs, parent, parent) : object 'fit_data' not found**


# the other format i tried was  as follows (option#2):
library(purrr)
library(broom)

models <- df %>%
  group_by(organ) %>%
  nest() %>%
  mutate(model = map(data, ~ glm(IHC ~ Dose, data = ., family = binomial(logit)),
         augmented= map2(model, data, augment,type.predict="reponse")))
models %>%unnest(augment)

# the error i get from option 2 is as follows
#models %>% unnest(augmented) Error: Can't subset columns that don't exist. x The column #augmented doesn't exist

In the example you are trying to duplicate. There is a left join where a table of data to predict on fit_data is referenced. In that example the fact that fit_data has a column named data in common with what it is joined to causes that column to be named data.y.
You have hard coded your own data.y.
Recommend you scrap your data.y and make a fit_data

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Ah! @nirgrahamuk thank you so much~