SlideShare a Scribd company logo
1 of 1
Download to read offline
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

More Related Content

More from akcopier1

If one of the students knows one-half of the list at time t = 0 and t.pdf
 If one of the students knows one-half of the list at time t = 0 and t.pdf If one of the students knows one-half of the list at time t = 0 and t.pdf
If one of the students knows one-half of the list at time t = 0 and t.pdfakcopier1
 
How do these two groups compare in terms of variability in MATH score.pdf
 How do these two groups compare in terms of variability in MATH score.pdf How do these two groups compare in terms of variability in MATH score.pdf
How do these two groups compare in terms of variability in MATH score.pdfakcopier1
 
Ido not understand V,VI and Part B IV and any help on how to fi.pdf
 Ido not understand V,VI and Part B IV and any help on how to fi.pdf Ido not understand V,VI and Part B IV and any help on how to fi.pdf
Ido not understand V,VI and Part B IV and any help on how to fi.pdfakcopier1
 
Identify elements associated with the preparation of a programmable l.pdf
 Identify elements associated with the preparation of a programmable l.pdf Identify elements associated with the preparation of a programmable l.pdf
Identify elements associated with the preparation of a programmable l.pdfakcopier1
 
Identify the main Transportation agents for the following types of so.pdf
 Identify the main Transportation agents for the following types of so.pdf Identify the main Transportation agents for the following types of so.pdf
Identify the main Transportation agents for the following types of so.pdfakcopier1
 
Identify all zero-force members. Solution1. roller load at F s.pdf
 Identify all zero-force members.  Solution1. roller load at F s.pdf Identify all zero-force members.  Solution1. roller load at F s.pdf
Identify all zero-force members. Solution1. roller load at F s.pdfakcopier1
 
I would appreciate you helping me do the following problem...PLEA.pdf
 I would appreciate you helping me do the following problem...PLEA.pdf I would appreciate you helping me do the following problem...PLEA.pdf
I would appreciate you helping me do the following problem...PLEA.pdfakcopier1
 
I need to calcuate the vertical analysis This is from the Financ.pdf
 I need to calcuate the vertical analysis This is from the Financ.pdf I need to calcuate the vertical analysis This is from the Financ.pdf
I need to calcuate the vertical analysis This is from the Financ.pdfakcopier1
 
I was able to figure out 2002 but not the rest Develop a.pdf
 I was able to figure out 2002 but not the rest Develop a.pdf I was able to figure out 2002 but not the rest Develop a.pdf
I was able to figure out 2002 but not the rest Develop a.pdfakcopier1
 
I hope this is clear this time.SolutionMoment of inertia is.pdf
 I hope this is clear this time.SolutionMoment of inertia is.pdf I hope this is clear this time.SolutionMoment of inertia is.pdf
I hope this is clear this time.SolutionMoment of inertia is.pdfakcopier1
 
I have a nephew Berkeley and niece Chelsea  who, when v.pdf
 I have a nephew Berkeley and niece Chelsea  who, when v.pdf I have a nephew Berkeley and niece Chelsea  who, when v.pdf
I have a nephew Berkeley and niece Chelsea  who, when v.pdfakcopier1
 

More from akcopier1 (11)

If one of the students knows one-half of the list at time t = 0 and t.pdf
 If one of the students knows one-half of the list at time t = 0 and t.pdf If one of the students knows one-half of the list at time t = 0 and t.pdf
If one of the students knows one-half of the list at time t = 0 and t.pdf
 
How do these two groups compare in terms of variability in MATH score.pdf
 How do these two groups compare in terms of variability in MATH score.pdf How do these two groups compare in terms of variability in MATH score.pdf
How do these two groups compare in terms of variability in MATH score.pdf
 
Ido not understand V,VI and Part B IV and any help on how to fi.pdf
 Ido not understand V,VI and Part B IV and any help on how to fi.pdf Ido not understand V,VI and Part B IV and any help on how to fi.pdf
Ido not understand V,VI and Part B IV and any help on how to fi.pdf
 
Identify elements associated with the preparation of a programmable l.pdf
 Identify elements associated with the preparation of a programmable l.pdf Identify elements associated with the preparation of a programmable l.pdf
Identify elements associated with the preparation of a programmable l.pdf
 
Identify the main Transportation agents for the following types of so.pdf
 Identify the main Transportation agents for the following types of so.pdf Identify the main Transportation agents for the following types of so.pdf
Identify the main Transportation agents for the following types of so.pdf
 
Identify all zero-force members. Solution1. roller load at F s.pdf
 Identify all zero-force members.  Solution1. roller load at F s.pdf Identify all zero-force members.  Solution1. roller load at F s.pdf
Identify all zero-force members. Solution1. roller load at F s.pdf
 
I would appreciate you helping me do the following problem...PLEA.pdf
 I would appreciate you helping me do the following problem...PLEA.pdf I would appreciate you helping me do the following problem...PLEA.pdf
I would appreciate you helping me do the following problem...PLEA.pdf
 
I need to calcuate the vertical analysis This is from the Financ.pdf
 I need to calcuate the vertical analysis This is from the Financ.pdf I need to calcuate the vertical analysis This is from the Financ.pdf
I need to calcuate the vertical analysis This is from the Financ.pdf
 
I was able to figure out 2002 but not the rest Develop a.pdf
 I was able to figure out 2002 but not the rest Develop a.pdf I was able to figure out 2002 but not the rest Develop a.pdf
I was able to figure out 2002 but not the rest Develop a.pdf
 
I hope this is clear this time.SolutionMoment of inertia is.pdf
 I hope this is clear this time.SolutionMoment of inertia is.pdf I hope this is clear this time.SolutionMoment of inertia is.pdf
I hope this is clear this time.SolutionMoment of inertia is.pdf
 
I have a nephew Berkeley and niece Chelsea  who, when v.pdf
 I have a nephew Berkeley and niece Chelsea  who, when v.pdf I have a nephew Berkeley and niece Chelsea  who, when v.pdf
I have a nephew Berkeley and niece Chelsea  who, when v.pdf
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 

Modeling a Prediction Equation in R for Personality Types and Drinking

  • 1. 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