library(ggplot2)
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
happyDat <- read.csv("C:/Users/garre/Downloads/World Hppiness Report 2021.csv")

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

  1. View your dataset in R Studio. (Do NOT write this code in your markdown file. just in the console.) What do you notice about it? (e.g. What variables are in the file?)

I notice there is both quantitative and qualitative data, our variables are the countryname, regionalindicator, generosity, socialsupport, and dystopia. ## Visualizing your data

  1. Print the regionalIndicator data (Hint: To print variable values, you only need to write data$column in a code chunk)
happyDat$regionalIndicator
##   [1] "Western Europe"                     "Western Europe"                    
##   [3] "Western Europe"                     "Western Europe"                    
##   [5] "Western Europe"                     "Western Europe"                    
##   [7] "Western Europe"                     "Western Europe"                    
##   [9] "North America and ANZ"              "Western Europe"                    
##  [11] "North America and ANZ"              "Middle East and North Africa"      
##  [13] "Western Europe"                     "North America and ANZ"             
##  [15] "Western Europe"                     "Latin America and Caribbean"       
##  [17] "Western Europe"                     "Central and Eastern Europe"        
##  [19] "North America and ANZ"              "Western Europe"                    
##  [21] "Western Europe"                     "Middle East and North Africa"      
##  [23] "Western Europe"                     "East Asia"                         
##  [25] "Middle East and North Africa"       "Middle East and North Africa"      
##  [27] "Western Europe"                     "Western Europe"                    
##  [29] "Central and Eastern Europe"         "Latin America and Caribbean"       
##  [31] "Latin America and Caribbean"        "Southeast Asia"                    
##  [33] "Central and Eastern Europe"         "Central and Eastern Europe"        
##  [35] "Latin America and Caribbean"        "Latin America and Caribbean"       
##  [37] "Latin America and Caribbean"        "Central and Eastern Europe"        
##  [39] "Western Europe"                     "Central and Eastern Europe"        
##  [41] "Latin America and Caribbean"        "Commonwealth of Independent States"
##  [43] "Latin America and Caribbean"        "Central and Eastern Europe"        
##  [45] "Commonwealth of Independent States" "Central and Eastern Europe"        
##  [47] "Middle East and North Africa"       "Central and Eastern Europe"        
##  [49] "Latin America and Caribbean"        "Sub-Saharan Africa"                
##  [51] "Central and Eastern Europe"         "Latin America and Caribbean"       
##  [53] "Central and Eastern Europe"         "Southeast Asia"                    
##  [55] "Latin America and Caribbean"        "East Asia"                         
##  [57] "Latin America and Caribbean"        "Western Europe"                    
##  [59] "Latin America and Caribbean"        "Central and Eastern Europe"        
##  [61] "Southeast Asia"                     "East Asia"                         
##  [63] "Latin America and Caribbean"        "Central and Eastern Europe"        
##  [65] "Commonwealth of Independent States" "Latin America and Caribbean"       
##  [67] "Commonwealth of Independent States" "Western Europe"                    
##  [69] "Latin America and Caribbean"        "East Asia"                         
##  [71] "Latin America and Caribbean"        "Central and Eastern Europe"        
##  [73] "Latin America and Caribbean"        "Western Europe"                    
##  [75] "Commonwealth of Independent States" "Commonwealth of Independent States"
##  [77] "East Asia"                          "Commonwealth of Independent States"
##  [79] "Southeast Asia"                     "Middle East and North Africa"      
##  [81] "Southeast Asia"                     "Southeast Asia"                    
##  [83] "Sub-Saharan Africa"                 "East Asia"                         
##  [85] "Sub-Saharan Africa"                 "Commonwealth of Independent States"
##  [87] "South Asia"                         "Central and Eastern Europe"        
##  [89] "South Asia"                         "Commonwealth of Independent States"
##  [91] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
##  [93] "Central and Eastern Europe"         "Central and Eastern Europe"        
##  [95] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
##  [97] "Commonwealth of Independent States" "Sub-Saharan Africa"                
##  [99] "Sub-Saharan Africa"                 "Southeast Asia"                    
## [101] "South Asia"                         "Sub-Saharan Africa"                
## [103] "Sub-Saharan Africa"                 "Middle East and North Africa"      
## [105] "South Asia"                         "Middle East and North Africa"      
## [107] "Latin America and Caribbean"        "Commonwealth of Independent States"
## [109] "Middle East and North Africa"       "Commonwealth of Independent States"
## [111] "Middle East and North Africa"       "Sub-Saharan Africa"                
## [113] "Sub-Saharan Africa"                 "Southeast Asia"                    
## [115] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
## [117] "Sub-Saharan Africa"                 "Middle East and North Africa"      
## [119] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
## [121] "Sub-Saharan Africa"                 "Middle East and North Africa"      
## [123] "Middle East and North Africa"       "Sub-Saharan Africa"                
## [125] "Middle East and North Africa"       "Southeast Asia"                    
## [127] "Middle East and North Africa"       "Sub-Saharan Africa"                
## [129] "South Asia"                         "Sub-Saharan Africa"                
## [131] "Sub-Saharan Africa"                 "Middle East and North Africa"      
## [133] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
## [135] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
## [137] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
## [139] "South Asia"                         "Sub-Saharan Africa"                
## [141] "Middle East and North Africa"       "Sub-Saharan Africa"                
## [143] "Latin America and Caribbean"        "Sub-Saharan Africa"                
## [145] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
## [147] "Sub-Saharan Africa"                 "Sub-Saharan Africa"                
## [149] "South Asia"
  1. Create a simple frequency table of regionalIndicator
table(happyDat$regionalIndicator)
## 
##         Central and Eastern Europe Commonwealth of Independent States 
##                                 17                                 12 
##                          East Asia        Latin America and Caribbean 
##                                  6                                 20 
##       Middle East and North Africa              North America and ANZ 
##                                 17                                  4 
##                         South Asia                     Southeast Asia 
##                                  7                                  9 
##                 Sub-Saharan Africa                     Western Europe 
##                                 36                                 21
  1. Describe what you see in the simple frequency table.

I see the names of each region and how much they appear

  1. What type of graph would be appropriate to show the regionalIndicator variable? Explain your answer

A bar graph would show the mode, and show each region.

  1. Create the graph that you chose in #4.
ggplot(happyDat, aes(regionalIndicator))+ geom_bar()

  1. What is the mode of regional indicator?
modeest::mfv(happyDat$regionalIndicator)
## [1] "Sub-Saharan Africa"
  1. Is the mode consistent with what is presented in your graph?

Yes, they are both sub saharan africa 8. Create a simple frequency table for socialSupport.

table(factor(happyDat$socialSupport,))
## 
## 0.463 0.489  0.49 0.537  0.54 0.552  0.56 0.569 0.603 0.619 0.626  0.63 0.636 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 0.639 0.641 0.644 0.651 0.671 0.672 0.686 0.688  0.69 0.691 0.693 0.697 0.702 
##     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 0.708  0.71  0.72 0.724 0.727 0.728  0.74 0.744 0.746  0.75 0.762 0.764 0.765 
##     1     3     1     1     1     1     1     1     1     2     1     1     1 
## 0.767  0.77 0.774 0.776 0.779 0.781 0.784 0.787 0.795 0.799 0.802 0.805  0.81 
##     1     1     1     1     1     1     1     1     1     2     2     1     1 
## 0.811 0.812 0.813 0.817 0.818  0.82 0.821 0.822 0.823 0.826 0.827  0.83 0.831 
##     2     1     1     1     1     1     2     1     1     1     2     1     1 
## 0.832 0.836 0.843 0.844 0.847 0.848  0.85 0.853 0.857 0.858  0.86 0.861 0.862 
##     3     2     1     1     1     1     1     1     1     1     2     1     1 
## 0.864  0.87 0.873 0.877 0.879  0.88 0.882 0.884 0.888 0.891 0.893 0.896 0.898 
##     1     1     1     1     1     1     2     1     2     2     2     1     3 
## 0.903 0.905 0.906 0.908  0.91 0.913 0.915 0.918  0.92 0.924 0.925 0.926 0.927 
##     2     1     1     1     1     1     1     1     1     1     1     1     1 
## 0.931 0.932 0.934 0.935 0.936 0.939  0.94 0.941 0.942 0.943 0.947 0.948 0.952 
##     2     1     3     2     1     1     1     1     3     1     2     2     1 
## 0.954 0.983 
##     3     2
  1. Create a grouped frequency table for socialSupport. You should use 10 intervals ins
cut2(happyDat$socialSupport, g=10)
##   [1] [0.942,0.983] [0.942,0.983] [0.942,0.983] [0.942,0.983] [0.942,0.983]
##   [6] [0.942,0.983] [0.925,0.942) [0.896,0.925) [0.942,0.983] [0.925,0.942)
##  [11] [0.925,0.942) [0.925,0.942) [0.896,0.925) [0.925,0.942) [0.942,0.983]
##  [16] [0.864,0.896) [0.925,0.942) [0.942,0.983] [0.896,0.925) [0.896,0.925)
##  [21] [0.942,0.983] [0.836,0.864) [0.925,0.942) [0.896,0.925) [0.836,0.864)
##  [26] [0.864,0.896) [0.925,0.942) [0.864,0.896) [0.942,0.983] [0.813,0.836)
##  [31] [0.925,0.942) [0.896,0.925) [0.813,0.836) [0.925,0.942) [0.864,0.896)
##  [36] [0.813,0.836) [0.864,0.896) [0.925,0.942) [0.776,0.813) [0.925,0.942)
##  [41] [0.896,0.925) [0.896,0.925) [0.864,0.896) [0.896,0.925) [0.942,0.983]
##  [46] [0.813,0.836) [0.836,0.864) [0.864,0.896) [0.720,0.776) [0.896,0.925)
##  [51] [0.925,0.942) [0.836,0.864) [0.942,0.983] [0.864,0.896) [0.864,0.896)
##  [56] [0.864,0.896) [0.896,0.925) [0.864,0.896) [0.776,0.813) [0.896,0.925)
##  [61] [0.813,0.836) [0.776,0.813) [0.813,0.836) [0.864,0.896) [0.836,0.864)
##  [66] [0.813,0.836) [0.864,0.896) [0.813,0.836) [0.776,0.813) [0.925,0.942)
##  [71] [0.864,0.896) [0.836,0.864) [0.836,0.864) [0.813,0.836) [0.896,0.925)
##  [76] [0.896,0.925) [0.836,0.864) [0.836,0.864) [0.836,0.864) [0.813,0.836)
##  [81] [0.813,0.836) [0.776,0.813) [0.463,0.644) [0.776,0.813) [0.644,0.720)
##  [86] [0.776,0.813) [0.720,0.776) [0.925,0.942) [0.896,0.925) [0.836,0.864)
##  [91] [0.644,0.720) [0.644,0.720) [0.644,0.720) [0.776,0.813) [0.720,0.776)
##  [96] [0.463,0.644) [0.942,0.983] [0.644,0.720) [0.463,0.644) [0.720,0.776)
## [101] [0.644,0.720) [0.463,0.644) [0.836,0.864) [0.813,0.836) [0.644,0.720)
## [106] [0.463,0.644) [0.836,0.864) [0.644,0.720) [0.776,0.813) [0.864,0.896)
## [111] [0.720,0.776) [0.776,0.813) [0.644,0.720) [0.720,0.776) [0.720,0.776)
## [116] [0.720,0.776) [0.720,0.776) [0.644,0.720) [0.776,0.813) [0.720,0.776)
## [121] [0.644,0.720) [0.644,0.720) [0.836,0.864) [0.813,0.836) [0.813,0.836)
## [126] [0.776,0.813) [0.720,0.776) [0.463,0.644) [0.813,0.836) [0.720,0.776)
## [131] [0.463,0.644) [0.720,0.776) [0.720,0.776) [0.776,0.813) [0.644,0.720)
## [136] [0.463,0.644) [0.644,0.720) [0.463,0.644) [0.463,0.644) [0.463,0.644)
## [141] [0.813,0.836) [0.644,0.720) [0.463,0.644) [0.463,0.644) [0.776,0.813)
## [146] [0.776,0.813) [0.463,0.644) [0.720,0.776) [0.463,0.644)
## 10 Levels: [0.463,0.644) [0.644,0.720) [0.720,0.776) ... [0.942,0.983]
  1. What type of graph is appropriate for the socialSupport data?

a frequency plot

  1. Create the graph you identified in #10.
ggplot(happyDat, aes(socialSupport)) +geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

  1. Create a histogram of the socialSupport data that uses 10 bins for the data.
ggplot(happyDat,aes(socialSupport)) +geom_histogram(bins = 10)