#R Code

#Data Preparation

## New names:
## * `% of Jungian Group` -> `% of Jungian Group...8`
## * `% of Jungian Group` -> `% of Jungian Group...10`

#Results #Data Summary #perform one tailed binomial tests on MBTI and Jungian groups #With no bias, genders would be normally distributed and prob(male) = prob(female) = 0.5. #k = smaller of n(Males) and n(Females) for each type, n = total number in group

#Results #Exploratory Data Analysis #Create Plots


#Introduction

This study analyses gender proportions for personality type within two models, the 16-type Myers-Briggs model (Myers, 1962) and Jung’s (2016) 8-type model.

Goetz et al (2020) found that of the 4 dichotomous scales in the MBTI, ie Thinking/Feeling, Intuition/Sensing, Introversion/Extraversion and Judging/Perceiving, female study participants were 2.96 more likely to choose the Feeling “function”, compared to males. Similarly, male participants were approximately 3 times more likely to choose the Thinking function.

Quenk, in Stern (1989) referenced a 1985 study by Myers and McCaulley, which reported a 65% female preference for the Feeling function and a 60% male preference for the Thinking function. The preferences in both these studies were for a function, rather than a type.

The Myers Briggs Type Indicator (MBTI) derives from Jung’s model. Jung uses 3 dichotomous scales, and the MBTI adds a fourth scale -Judging/Perceiving. Boyle (1995) highlights psychometric limitations with the MBTI model. One could therefore question the justification for adding a fourth scale. Hence the relevance of looking at both models.

Phenotype /genotype data exists on PheGeni for personality traits, in particular the “Big 5 traits” but not types. Lo et al. (2017) found 6 genomic loci relating to trait phenotypes.

Genomic data relating to MBTI types is currently being collected in a study run by Dr Denise Cook in Canada through her web-site, personalitygenie.com. Through email correspondence with Denise, I gathered she is aiming for a large sample to account for type classification errors. It is taking a long time to recruit a sufficient number of participants.

#Objective

In the Jungian and MBTI models, it may be reasonable to describe the Thinking function as male-oriented, and the Feeling function as female-oriented.

The objective of this study is to assess if it is reasonable to describe…

..8 of the MBTI types as male-oriented and 8 of the types as female-oriented, and ..4 of the Jungian types as male-oriented and 4 of the types as female-oriented.

#Hypothesis

In statistical terms, the 8 “Thinking” MBTI types contain significantly more males, and the 8 “Feeling” types contain significantly more females. In statistical terms, the 4 “Thinking” Jungian types contain significantly more males, and the 4 “Feeling” types contain significantly more females.

#Project Population

A study by Hammer and Mitchell (1996) aimed to establish a base-line distribution of MBTI types within the US population, analysed across gender, age, socio-economic status and ethnic group.

Approximately 2600 participants were surveyed over a 3-year period from 1988 to 1991. Each participant self-completed the Form G of the MBTI, supervised by a team of test-site coordinators.

The participants were community members from 4 broad geographical areas, matching areas used in the census. The sample was stratified and reduced to match distributions by gender, age, socio-economic status and ethnicity within the census data. There was no longitudinal analysis.

Hammer and Mitchell also included sample randomisation to remove biases and help ensure the final sample was representative of the 1990 US Census population.

This study will use the Hammer and Mitchell data. The 16 MBTI types will be paired down to 8 Jungian types by removing Myers-Briggs’ fourth dichotomy -Judging/Perceiving.

#Variables of Interest

For the purposes of this research, socio-economic status and ethnicity are irrelevant. Hammer and Mitchell stratified their sample by age into children (293) and adult (1267). Like Hammer and Mitchell’s, this study will only analyse adult participants.

There are 2 categorical variables of interest, gender and personality type.

#Ethics Statement

Following completion and submission of ECU’s Proportional Review Checklist, this research has been provisionally exempted from a Human Research Ethics Review. This is subject to satisfactory completion and submission of a Data Management Plan. ECU advised that this ought not be submitted until reviewed by the research supervisor. This advice is attached in Appendix 2, and ECU’s email in Appendix 2a.

#Data Preparation

  1. Copy sample numbers and gender percentages in each of the 16 MBTI groups into an Excel spreadsheet and then import into R.
  2. Convert the 16 MBTI types to Jungian types (Table 1 in Appendix 1).
  3. Tabulate gender numbers and percentages for each type in each model. These are shown in Appendix 3 as Table 3.
  4. Create dataframes for both models showing for each type, the group total and the count of the less frequent gender. These are the numbers that will be used in the binomial tests. (Appendix 4, Tables 4a and 4b).

#Statistical Analyses

A Null hypothesis would state there is no gender bias within each group. So for any participant chosen at random from any type group, p(Male) =p(Female) =0.5 Gender is the independent variable, personality type the dependent.

Test the gender split of the types within each model to see if it is statistically significant, as follows…

  1. A one sample, one tailed binomial tests will run on each type, comparing the actual gender proportion against the expected proportion of 0.5.
  2. P values will be calculated for each type within each model.
  3. The significance of the p-values will be analysed, at varying confidence levels.

No additional steps will be taken to control for covariates. Hammer and Mitchell controlled for covariates as follows…

  1. Several participants were not willing to complete the lengthy questionnaire. This led to an increased sample proportion of ethnically-white females. This was controlled for with a stratification process. A number of random samples were taken until the sample proportion of ethnically-white females matched the census data.
  2. Geographical bias was controlled for by randomly selecting 60 test sites from the 4 broad geographical areas. 27 of the 50 US states were represented.
  3. “Incompetent” administration of the questionnaire was controlled for by using test site coordinators who were all familiar with test administration and data collection.

#Results #Data Summary

#Table 5a below shows the p values for the 16 MBTI types

##                                     p upper_ci actual_prob MBTI Types
## Less Frequent MBTI Gender   1.003e-02   0.4394      0.2812       ENFJ
## Less Frequent MBTI Gender1  2.170e-01   0.5480      0.4500       ENFP
## Less Frequent MBTI Gender2  7.884e-10   0.3009      0.2295       ESFJ
## Less Frequent MBTI Gender3  3.155e-03   0.4357      0.3333       ESFP
## Less Frequent MBTI Gender4  2.891e-09   0.3268      0.2603       ISFJ
## Less Frequent MBTI Gender5  7.694e-05   0.3570      0.2456       ISFP
## Less Frequent MBTI Gender6  8.138e-02   0.5216      0.3636       INFJ
## Less Frequent MBTI Gender7  5.000e-01   0.6091      0.4909       INFP
## Less Frequent MBTI Gender8  1.553e-01   0.5528      0.4000       ENTJ
## Less Frequent MBTI Gender9  4.321e-03   0.4358      0.3220       ENTP
## Less Frequent MBTI Gender10 7.909e-03   0.4657      0.3889       ESTJ
## Less Frequent MBTI Gender11 6.187e-02   0.5067      0.3934       ESTP
## Less Frequent MBTI Gender12 9.395e-03   0.4749      0.4141       ISTJ
## Less Frequent MBTI Gender13 7.000e-03   0.4547      0.3580       ISTP
## Less Frequent MBTI Gender14 2.438e-02   0.4754      0.3409       INTJ
## Less Frequent MBTI Gender15 8.764e-02   0.5178      0.4091       INTP
## Less Frequent MBTI Gender16 2.802e-02   0.4963      0.4728      Total

#Table 5b below show p values for the 8 Jungian types

##                                       p upper_ci actual_prob Jungian Types
## Less Frequent Jungian Gender  2.337e-02   0.4837      0.4018           ENF
## Less Frequent Jungian Gender1 3.796e-11   0.3254      0.2680           ESF
## Less Frequent Jungian Gender2 1.097e-12   0.3115      0.2562           ISF
## Less Frequent Jungian Gender3 1.687e-01   0.5364      0.4432           INF
## Less Frequent Jungian Gender4 2.539e-03   0.4401      0.3511           ENT
## Less Frequent Jungian Gender5 1.667e-03   0.4527      0.3904           EST
## Less Frequent Jungian Gender6 3.854e-04   0.4485      0.3978           IST
## Less Frequent Jungian Gender7 8.373e-03   0.4643      0.3818           INT
## Less Frequent Jungian Gender8 2.802e-02   0.4963      0.4728         Total

#Results #Exploratory Data Analysis

All “Feeling” types had a higher percentage of females. All “Thinking” types had a higher percentage of males. This was true in both the MBTI and Jung groups. This shows the results reported by Goetz et al. (2020) and Myers and Stern (1989) regarding the Thinking/Feeling scale, can be extended to individual types, in both models.

#Plot 1 : P values for each MBTI type. Significance of these p values is shown by the 3 coloures horizontal lines.

The plot shows, of the 16 MBTI types… 10 have a p-value indicating a significant gender bias at a 95% confidence level or higher 3 have a p-value indicating a significant gender bias at a confidence level between 90% and 95% 2 have a p-value indicating a significant gender bias at a confidence level or between 77% and 90% 1 has a p-value indicating a significant gender bias at a 50% confidence level

#Plot 2 : P values for each Jungian type. Significance of these p values is shown by the 3 coloures horizontal lines.

The plot shows, of the 8 Jungian types… 6 have a p-value indicating a significant gender bias at a 99% confidence level or higher 1 has a p-value indicating a significant gender bias at a confidence level between 95% and 99% 1 has a p-value indicating a significant gender bias at a confidence level of 83%

#Results #Final Data Analysis & Discussion

Plot 2 shows that gender biases can be extended to all Jungian types at high confidence levels. Plot 1 shows that the same cannot be done for all MBTI types.

The gender bias in Jungian types is clear and universal, but not so for MBTI types. Within the MBTI community, types are not currently associated with genders. This does not necessarily mean types ought not be differentiated according to gender. Instead, the MBTI’s inability to clearly differentiate could be further evidence that the “arbitrary” addition of a 4th dichotomous scale by Myers and Briggs on top of Jung’s model was a mistake.

This research indicates gender can justifiably replace Jung’s 3rd dichotomous scale -Thinking/Feeling, as a more appropriate 3rd dichotomy.

Arguably, the thinking/feeling dichotomy is no longer relevant in today’s world. Using it can lead one to the assumption that males think more than females, and females feel more than males. No evidence exists to support this assumption.

Jung wrote his seminal work “Psychologische Typen” in 1921. He created the thinking/ feeling dichotomy at a time when gender roles in society were very different than today. There were fewer females in skilled/ highly skilled jobs, where “thinking” processes are important. Similarly, significantly more females were in caring roles, especially in the home, where “feeling” processes are important. In today’s world many more males are in caring roles such as nursing, disability support and child raising. Similarly, many more females are employed in skilled and highly skilled jobs.

Jung’s creation of the scale, together with subsequent studies such as Hammer and Mitchell’s, which associated thinking traits with males and feeling traits with females, are arguably responsible for reinforcing gender stereotypes that are misleading.

Using gender to differentiate type instead of the Thinking/Feeling scale is a lot easier and also less misleading.

#Study Limitations

Hammer and Mitchell’s research uses a self-completion questionnaire, the MBTI Form G. As with any such questionnaire, there is potential for subjective bias leading to incorrect type classification. The authors do not acknowledge this. The existence and size of any bias is undetermined. Classification errors could have significantly impacted their results and analysis.

#Confirm the Results by testing Equivalent Datasets

Hammer and Mitchell referenced 3 earlier studies of MBTI type and gender. One is by the Stanford Research Institute, one by the Center for Applications of Psychological Type (CAPT) and one by Myers on high school students from Pennsylvania. Data from these studies is compiled in Macdaid et al.(1991). The main focus of these studies was MBTI type and occupation.

The CAPT study has a sample size of 32,671, made up of 16,880 females and 15,791 males. All completed the MBTI Form G and were classified into types. I now have this data, thanks to an ECU inter-library loan. It would be interesting and relatively easy to run this much larger sample through the r script here, to confirm the results of this study.

#Conclusions

This study tested if there is evidence to suggest that half of the MBTI and Jungian types can be described as male types, and the other half female types. The results showed there is strong evidence for this in the Jungian model (Plot 1) and weaker evidence in the MBTI model (Plot 2). The results have interesting implication for future research, as discussed below.

#Implications for Future Research

To date, the genetic determinants of personality type (rather than traits), are unknown.

If gender is a determinant of personality type, the process of discovering a “personality gene” becomes much easier.

This study suggests, of 8 Jungian phenotypes, 4 are male types and 4 female types. Given that the genetic locus of type would be the same for males and females, one only needs to run a Genome Wide Association Study (GWAS) on one gender and 4 phenotypes.

Compared to studying 8 phenotypes, (or 16 if one is using the MBTI model), sample sizes can be significantly reduced. Sample size is currently a limiting factor in generating genotype/phenotype data in this field of research.

Even more interesting is the fact that there are 4 SNP variants in the human genome, a, c, t and g. It is not beyond the realms of possibility that personality type could simply be a function of whether one has the a ,c g or t variant at the relevant locus on the genome.

If one were to study this further, the obvious starting point would be to look at tetra-allelic SNPs, ie SNPs that have all 4 variants.

The other significant barrier is accurate type classification, as discussed above. What classification system can one use to reduce errors? If one assumes 4 types, only two dichotomous scales are needed. Both Jung and the “Big 5 Personality Traits” model studied by Lo et al. (2017) use the extraversion/intraversion scale. Consequently phenotype/genotype data already exists for this and it makes sense to use it. An advantage of using the scale is it can be confirmed objectively. If one self-identifies as extravert, for example, others can confirm this objectively by observation.

Jung’s other dichotomous scale is Sensing/Intuition. Genotype data on this phenotype is being collected by Dr Cook, however she is using self-completion questionnaires, with their inherent problems.

In his seminal work, Sheldon (1954) classified people by somatotype (body shape) into 3 categories -Ectomorph (thin), Endomorph(fuller-bodied) and Mesomorph (muscular). One could argue that his third type is a function of exercise levels as much as genetics. Consequently, there is some justification for simply using ectomorph / endomorph as a dichotomous scale.

The advantage of using this scale is it can be measured by objective observation, together with discussions with the participant regarding their typical body shape over time. One could also use body/mass indices.

To date no scientific correlation has been established between somatotype and MBTI/Jungian personality type. A correlation could however exist. The research I plan to conduct would use this as a second dichotomous scale.

#References

  1. Myers, I. B. (1962). The Myers-Briggs Type Indicator: Manual (1962). Consulting Psychologists Press.

https://doi.org/10.1037/14404-000

  1. Jung, C. (2016). Psychological Types. Routledge. https://doi.org/10.4324/9781315512334

  2. Goetz, M. et al (2020, July). An Examination of Myers-Briggs Type Indicator Personality, Gender, and Career Interests of Ontario Veterinary College Students. Journal of Veterinary Medical Information. https://jvme.utpjournals.press/doi/full/10.3138/jvme.0418-044r

  3. Stern, E. M. (1989). Psychotherapy and the self contained patient (Ser. The psychotherapy patient series). Haworth. https://books.google.com.au/books?hl=en&lr=&id=NYymks6GfSUC&oi=fnd&pg=PA263&dq=Jungian+psychological+types+and+gender&ots=C0PrCyrIFf&sig=HaLr5NI3SmnHqyVRbnV7faaWFIc&redir_esc=y#v=onepage&q&f=false

  4. Boyle, G.J. (1995). Myers-Briggs Type Indicator (MBTI): Some Psychometric Limitations. Australian Psychological Society https://doi.org/10.1111/j.1742-9544.1995.tb01750.x

  5. Lo, MT., Hinds, D., Tung, J. et al. Genome-wide analyses for personality traits identify six genomic loci and show correlations with psychiatric disorders. Nat Genet 49, 152–156 (2017). https://doi.org/10.1038/ng.3736

  6. Hammer, A.L. & Mitchell, W. D (1996). The Distribution of MBTI Types In the US by Gender and Ethnic Group. Journal of Psychological Type. https://www.capt.org/jpt/pdfFiles/Hammer_A_and_Mitchell_W_Vol_37_2_15.pdf

  7. Macdaid, G. P., McCaulley, M. H., & Kainz, R. I. (1991). Myers-briggs type indicator atlas of type tables. Center for Applications of Psychological Type.

  8. Sheldon, W. A. (1954). Atlas of men, a guide for somatotyping the adult male at all ages.

  9. R packages used….tidyverse, readxl, kableExtra, ggpubr, readr, writexl, BiocManager, scales, broom, ggplot2

#Appendix 1 #Table 1 #MBTI types and the corrsponding Jungian Type

## # A tibble: 16 x 4
##    `MBTI Type` `MBTI Description`                `Jungian Type` `Jungian Descr~`
##    <chr>       <chr>                             <chr>          <chr>           
##  1 ENFJ        Extrovert, Intuitive, Feeling, J~ ENF            Extrovert, Intu~
##  2 ENFP        Extrovert, Intuitive, Feeling, P~ <NA>           <NA>            
##  3 ESFJ        Extrovert, Sensing, Feeling, Jud~ ESF            Extrovert, Sens~
##  4 ESFP        Extrovert, Sensing, Feeling, Per~ <NA>           <NA>            
##  5 ISFJ        Introvert, Sensing, Feeling, Jud~ ISF            Introvert, Sens~
##  6 ISFP        Introvert, Sensing, Feeling, Per~ <NA>           <NA>            
##  7 INFJ        Introvert, Intuitive, Feeling, J~ INF            Introvert, Intu~
##  8 INFP        Introvert, Sensing, Feeling, Per~ <NA>           <NA>            
##  9 ENTJ        Extrovert, Intuitive, Thinking, ~ ENT            Extrovert, Intu~
## 10 ENTP        Extrovert, Intuitive, Thinking, ~ <NA>           <NA>            
## 11 ESTJ        Extrovert, Sensing, Thinking, Ju~ EST            Extrovert, Sens~
## 12 ESTP        Extrovert, Sensing, Thinking, Pe~ <NA>           <NA>            
## 13 ISTJ        Introvert, Sensing, Thinking, Ju~ IST            Introvert, Sens~
## 14 ISTP        Introvert, Sensing, Thinking, Pe~ <NA>           <NA>            
## 15 INTJ        Introvert, Intuitive, Thinking, ~ INT            Introvert, Intu~
## 16 INTP        Introvert, Intuitive, Thinking, ~ <NA>           <NA>

#Appendix 2 #Ethical Clearance

“Dear Mr Falcongreen

EXEMPT FROM HUMAN RESEARCH ETHICS REVIEW -

PROJECT: Analysis of Jungian Psychological Type and Gender REMS NO: 2022-03341-FALCONGREEN Student No: 10533693

Thank you for completing ECU’s Proportional Review Checklist for the above project. Based on your responses to the questions asked and the University’s implementation of the ethics guidelines, it appears that this activity may be exempt from the University’s research ethics arrangements. Next Steps – Data Management Plan Before your research project commences, ECU requires you (as per the Australian Code for Responsible Conduct of Research and section 3.1.45 of the National Statement on Ethical Conduct in Human Research) to complete a Data Management Plan that addresses your intentions in relation to storing, securing, retaining and providing access to any collected or generated research data. Please commence your data management plan. Once submitted and accepted, you will receive: • Confirmation that your study is out of scope of the university’s ethics arrangements; • Acceptance of your data management plan; and • Access to your centrally provisioned digital data storage space through SharePoint.

If you need further information please see the data management and data management planning webpages or please contact This email DOES NOT constitute ethics approval. Approval for this research will only be granted after the completion of a Data Management Plan.

Yours sincerely

Manager, Research Governance Research Services. ”

#Appendix 2a #ECU Email- Notice from the Data Management Plan Submission page…

“Exempt Application Data Management Plan

Students, before submitting, please ensure that your supervisor has reviewed the application and an email or other correspondence from your supervisor confirming that the application can be submitted is also uploaded to the Attachments tab.”

#Appendix 3 #Tables 3 #Gender numbers and percentages for each type in each model

## # A tibble: 17 x 13
##    `MBTI Type` `MBTI Description`              `n  (MBTI Fema~` `n    (MBTI Ma~`
##    <chr>       <chr>                                      <dbl>            <dbl>
##  1 ENFJ        Extrovert, Intuitive, Feeling,~               23                9
##  2 ENFP        Extrovert, Intuitive, Feeling,~               44               36
##  3 ESFJ        Extrovert, Sensing, Feeling, J~               94               28
##  4 ESFP        Extrovert, Sensing, Feeling, P~               48               24
##  5 ISFJ        Introvert, Sensing, Feeling, J~              108               38
##  6 ISFP        Introvert, Sensing, Feeling, P~               43               14
##  7 INFJ        Introvert, Sensing, Feeling, J~               21               12
##  8 INFP        Introvert, Sensing, Feeling, P~               28               27
##  9 ENTJ        Extrovert, Intuitive, Thinking~               14               21
## 10 ENTP        Extrovert, Intuitive, Thinking~               19               40
## 11 ESTJ        Extrovert, Sensing, Thinking, ~               49               77
## 12 ESTP        Extrovert, Sensing, Thinking, ~               24               37
## 13 ISTJ        Introvert, Sensing, Thinking, ~               82              116
## 14 ISTP        Introvert, Sensing, Thinking, ~               29               52
## 15 INTJ        Introvert, Intuitive, Thinking~               15               29
## 16 INTP        Introvert, Intuitive, Thinking~               27               39
## 17 Total       <NA>                                         668              599
## # ... with 9 more variables: `MBTI Group Total` <dbl>, `Jungian Type` <chr>,
## #   `n (Jung Females)` <dbl>, `% of Jungian Group...8` <dbl>,
## #   `n   (Jung Males)` <dbl>, `% of Jungian Group...10` <dbl>,
## #   `Jungian Group Total` <dbl>, `Less Frequent MBTI Gender` <dbl>,
## #   `Less Frequent Jungian Gender` <dbl>

#Appendix 4 #Table 4a #For MBTI Types, group total and count for the less frequent gender in the group

## # A tibble: 17 x 2
##    `MBTI Group Total` `Less Frequent MBTI Gender`
##                 <dbl>                       <dbl>
##  1                 32                           9
##  2                 80                          36
##  3                122                          28
##  4                 72                          24
##  5                146                          38
##  6                 57                          14
##  7                 33                          12
##  8                 55                          27
##  9                 35                          14
## 10                 59                          19
## 11                126                          49
## 12                 61                          24
## 13                198                          82
## 14                 81                          29
## 15                 44                          15
## 16                 66                          27
## 17               1267                         599

#Table 4b #For Jungian Types, group total and count for the less frequent gender in the group

## # A tibble: 9 x 2
##   `Jungian Group Total` `Less Frequent Jungian Gender`
##                   <dbl>                          <dbl>
## 1                   112                             45
## 2                   194                             52
## 3                   203                             52
## 4                    88                             39
## 5                    94                             33
## 6                   187                             73
## 7                   279                            111
## 8                   110                             42
## 9                  1267                            599

#Appendix 5 #R Code

#R Code

#Data Preparation

#Load the Hammer and Mitchell data from Excel
project_data<-read_excel("C:/Users/mfalc/OneDrive - Edith Cowan University/Clinical Bioinformatics/Assessment 2/Data/Hammer_Mitchell_Data.xlsx", sheet = "Jungian_Types")
## New names:
## * `% of Jungian Group` -> `% of Jungian Group...8`
## * `% of Jungian Group` -> `% of Jungian Group...10`
#create new columns, showing the smaller of N(Females) and N(Males), and add to dataframe
project_data$"Less Frequent MBTI Gender"<-pmin(project_data$`n  (MBTI Females)`, project_data$`n    (MBTI Males)`)
project_data$"Less Frequent Jungian Gender"<-pmin(project_data$`n (Jung Females)`, project_data$`n   (Jung Males)`)


#create dataframe for binomial testing on MBTI groups and remove na's
bt_mbti<-select(project_data, `MBTI Group Total`, `Less Frequent MBTI Gender`)
bt_mbti<-na.omit(bt_mbti)


#create dataframe for binomial testing on Jungian groups and remove na's
bt_jung<-select(project_data, `Jungian Group Total`, `Less Frequent Jungian Gender`)
bt_jung<-na.omit(bt_jung)

#Results #Data Summary #perform one tailed binomial tests on MBTI and Jungian groups #With no bias, genders would be normally distributed and prob(male) = prob(female) = 0.5. #k = smaller of n(Males) and n(Females) for each type, n = total number in group

#define function and format output
bt<-function(k, n, p) {res<-binom.test(k, n, p, alternative = "less")
 out<-signif((data.frame(res$p.value, res$conf.int[2], res$estimate)), digits=4) 
 names(out)<-c("p", "upper_ci", "actual_prob")
 return(out)}

#apply it to each row of mbti dataframe
mbti_res<-do.call("rbind.data.frame", apply(bt_mbti, 1, function(row_i){bt(k=row_i["Less Frequent MBTI Gender"], n=row_i["MBTI Group Total"], p=0.5)}))
#Add MBTI types to output dataframes for easier reference
mbti_res$"MBTI Types"<-project_data$`MBTI Type`

#apply function to each row of jung dataframe
jung_res<-do.call("rbind.data.frame", apply(bt_jung, 1, function(row_i){bt(k=row_i["Less Frequent Jungian Gender"], n=row_i["Jungian Group Total"], p=0.5)}))
#Add Jung types to output dataframes for easier reference
jung_res$"Jungian Types"<-c("ENF","ESF","ISF","INF","ENT","EST","IST","INT","Total")

#Results #Exploratory Data Analysis #Create Plots

#create bar plots with ggplot2 to illustrate the results

#create MBTI plot, adding horizontal lines to indicate significance levels

ggp_mbti<-data.frame(group=mbti_res$`MBTI Types`, values=mbti_res$p)
CL95<-0.05  #create label variable for 95% Confidence Level
CL90<-0.1   #create label variable for 90% Confidence Level
CL50<-0.5   #create label variable for 50% Confidence Level
plot1<-ggplot(ggp_mbti, aes(x=group, y=values)) +
  geom_bar(stat="identity") +
  ggtitle("MBTI Types and P Value") +
  xlab("MBTI Type") +
  ylab("P Value") +
  geom_hline(yintercept=0.05, linetype="dashed", color="red", size=1.5) + #95% confidence level
  geom_text(aes(0, CL95, label= "95% Confidence Level", vjust= -1, hjust=-1)) + #label 95% line
  geom_hline(yintercept=0.1, linetype="dashed", colour="blue", size =1.5) + #90% confidence level
  geom_text(aes(0, CL90, label= "90% Confidence Level", vjust= -1, hjust=-1)) + #label 90% line
  geom_hline(yintercept=0.5, linetype="dashed", colour="orange", size =1.5) + #50% confidence level
  geom_text(aes(0, CL50, label= "50% Confidence Level", vjust= -1, hjust=-1)) + #label 50% line
  scale_y_continuous(limit =c(0, 0.55)) #adjust range of y axis to include all text
  

#create Jungian plot, adding horizontal lines to indicate significance levels

ggp_jung<-data.frame(group=jung_res$`Jungian Types`, values=jung_res$p)
CL95<-0.05   #create label variable for 95% Confidence Level
CL83<-0.17   #create label variable for 83% Confidence Level
CL99<-0.01   #create label variable for 99% Confidence Level
plot2<-ggplot(ggp_jung, aes(x=group, y=values)) +
  geom_bar(stat="identity") +
  ggtitle("Jungian Types and P Value") +
  xlab("Jungian Type") +
  ylab("P Value") +
  geom_hline(yintercept=CL95, linetype="dashed", color="red", size=1.5) + #95% CL
  geom_text(aes(0, CL95, label= "95% Confidence Level", vjust= -1, hjust=-1)) + #label 95% line
  geom_hline(yintercept=0.17, linetype="dashed", colour="purple", size =1.5) + #83% CL
  geom_text(aes(0, CL83, label= "83% Confidence Level", vjust= -1, hjust=-1)) + #label 83% line
  geom_hline(yintercept=0.01, linetype="dashed", colour="green", size =1.5) + #99% CL
  geom_text(aes(0, CL99, label= "99% Confidence Level", vjust= -1, hjust=-1)) +  #label 99% line
  scale_y_continuous(limit =c(0, 0.18)) #adjust range of y axis to include all text