I've got sample data of the prevalence of a certain characteristic in two different groups, with prevalence in group 1 being 65% and prevalence in group 2 40%:
# Generate data where the presence of the characteristic is higher in group 1 compared to group 2.
group_1 <- data.frame(id=as.numeric(1:100),
presence=factor(sample(c("Yes", "No"), 100, replace=T, prob=c(0.65, 0.35)), levels=c("No", "Yes")),
group=factor("Group 1", levels=c("Group 1", "Group 2")))
group_2 <- data.frame(id=as.numeric(101:200),
presence=factor(sample(c("Yes", "No"), 100, replace=T, prob=c(0.4, 0.6)), levels=c("No", "Yes")),
group=factor("Group 2", levels=c("Group 1", "Group 2")))
data <- rbind(group_1, group_2)
rm(group_1, group_2)
I'm trying to find a way to do the following: 'if you have a sample with a prevalence of x% of group 1 persons, then thís would be the predicted prevalence if they were in group 2'. I thought I should do this with logistic regression, but I don't think I'm finding what I need:
# Logistic regression model: how is presence in group 1 related to the presence in group 2.
model <- data %>% glm(formula=presence ~ group, family=binomial, data=.)
summary(model) # The regression formula is log(p/1-p) = -0.4895 + 0.9791 * Group 1
# The probability being present/prevalent in group 2 that follow from this model would then be:
exp(-0.4895 + 0.9791) / (exp(-0.4895*1 + 0.9791) + 1) # 0.62
I'm pretty sure the 0.62 is not something I'm looking for, but I'm also not sure what number I ám looking for.