Hi, I\'d like some help on modeling a prediction equation in R. Here\'s the relevant information: Table 4.13 shows the result of cross classifying a sample of people from the MBTI Step II National Sample on whether they report drinking alcohol frequently (1=yes,0=no) and on the four binary scales of the Myers-Briggs personality test: Extroversion/Introversion (E/I), Sensing/iNtuitive (S/N), Thinking/Feeling (T/F) and Judging/Perceiving (J/P). The 16 predictor combinations correspond to the 16 personality types: ESTJ, ESTP, ESFJ, ESFP, ENTJ, ENTP, ENFJ, ENFP, ISTJ, ISTP, ISFJ, ISFP, INTJ, INTP, INFJ, INFP. Here is a screenshot of the table: The question reads: Fit a model using the four scales as predictors of pi = the probability of drinking alcohol frequently. Report the prediction equation, specifying how you set up the indicator variables. I\'ve tried creating HUGE data frames with binary values and listing repeated E\'s, I\'s, etc., but that all seems far too tedious. Can somebody please help me out? The solution is logit(pi.hat) = -2.47 + 0.55EI - 0.43SN + 0.69TF - 0.20JP, but I\'m more interested in how the code and how to set it up. Please provide R code, Thanks! Solution n <- 100 MBdrink <- data.frame( EI=sample(c(\"E\",\"I\"), n, replace=TRUE), SN=sample(c(\"S\",\"N\"), n, replace=TRUE), TF=sample(c(\"T\",\"F\"), n, replace=TRUE), JP=sample(c(\"J\",\"P\"), n, replace=TRUE), Drink=factor( sample(c(\"Rarely\",\"Often\"), n, p=c(.2,.8), replace=TRUE), levels=c(\"Rarely\", \"Often\")), Count=rpois(n,5) ) library(plyr) MBdrink <- ddply(MBdrink, c(\"EI\",\"SN\",\"TF\",\"JP\",\"Drink\"), summarize, Count=sum(Count)) # dis-aggregate the data d <- ddply(MBdrink, \"Count\", function (u) do.call( rbind, replicate(unique(u$Count), u, simplify=FALSE))) # Run the regression you want r <- glm( Drink ~ EI + SN + TF + JP, data=d, family=binomial(link=\"logit\") # Logistic regression ) result <- cbind(d, Probability=predict(r, type=\"response\")) result <- unique(result) result <- result[order(result$Probability),] result.