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

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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Recently uploaded (20)

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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

Hi, Id like some help on modeling a prediction equation in R. Her.pdf

  • 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