Poisson and prediction

446 views Asked by At

I am new to R and need to know how to keep the variable 'gender' at its constant mean in order to make a prediction after using a Poisson regression analysis on data about doctor visits. This is a sample of my data:

visits gender    illness    age.category

   1 female       1          <30
   1 female       1          <30
   1   male       3          <30
   1   male       1          <30
   1   male       2          <30
   1 female       5          <30
   1 female       4          <30
   1 female       3          <30
   1 female       2          <30
   1   male       1          <30

I have been given the example (see below) of how to predict rates of visits to a doctor over a two week period for men and for women (whilst holding age and illness at constant means).

sex <- factor(c('female', 'male',))
avg.age <- mean(DoctorVisits$age)
avg.illness <- mean(DoctorVisits$illness)

hypothetical.person <- expand.grid(age=avg.age,
                               gender=sex,
                               illness=avg.illness)

predict(M.dr, 
    newdata = hypothetical.person,
    type = 'response')

But I need to predict rates of visits to a doctor over a two week period for age groups (whilst holding sex and illness at their constant means). Yet, I do not know how to keep gender at its constant mean. How do I ensure this?

1

There are 1 answers

2
Roman Luštrik On

Here is how I would create a data.frame for all different illness levels according to male and female and their average illness.

xy <- read.table(text = "visits gender    illness    age.category
                 1 female       1          <30
                 1 female       1          <30
                 1   male       3          <30
                 1   male       1          <30
                 1   male       2          <30
                 1 female       5          <30
                 1 female       4          <30
                 1 female       3          <30
                 1 female       2          <30
                 1   male       1          <30", header = TRUE)

xy

sex <- factor(c('female', 'male'))
age.groups <- c("< 30", "30-50", "> 50")
avg.illness.by.gender <- aggregate(illness ~ gender, data = xy, FUN = mean)

out <- expand.grid(gender = sex, age = age.groups)
out[out$gender == "female", "illness"] <- avg.illness.by.gender[avg.illness.by.gender$gender == "female", "illness"]
out[out$gender == "male", "illness"] <- avg.illness.by.gender[avg.illness.by.gender$gender == "male", "illness"]
out

  gender   age  illness
1 female  < 30 2.666667
2   male  < 30 1.750000
3 female 30-50 2.666667
4   male 30-50 1.750000
5 female  > 50 2.666667
6   male  > 50 1.750000