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