Basic Loading and Transformation

I have chosen to work with the dataset “weather-check.csv” from the author of “Where People Go To Check The Weather”, Walt Hickey found on the fivethirtyeight blog website.

-Loading the packages

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

-Loading the dataset from my github repository

weather <- read.csv("https://raw.githubusercontent.com/xhuliaturkaj/DATA-607/main/weather-check.csv",  header = TRUE, row.names = 1)

head(weather)
##            Do.you.typically.check.a.daily.weather.report.
## 3887201482                                            Yes
## 3887159451                                            Yes
## 3887152228                                            Yes
## 3887145426                                            Yes
## 3887021873                                            Yes
## 3886937140                                            Yes
##                          How.do.you.typically.check.the.weather.
## 3887201482                 The default weather app on your phone
## 3887159451                 The default weather app on your phone
## 3887152228                 The default weather app on your phone
## 3887145426                 The default weather app on your phone
## 3887021873 A specific website or app (please provide the answer)
## 3886937140 A specific website or app (please provide the answer)
##            A.specific.website.or.app..please.provide.the.answer.
## 3887201482                                                     -
## 3887159451                                                     -
## 3887152228                                                     -
## 3887145426                                                     -
## 3887021873                                            Iphone app
## 3886937140                                       AccuWeather App
##            If.you.had.a.smartwatch..like.the.soon.to.be.released.Apple.Watch...how.likely.or.unlikely.would.you.be.to.check.the.weather.on.that.device.
## 3887201482                                                                                                                                  Very likely
## 3887159451                                                                                                                                  Very likely
## 3887152228                                                                                                                                  Very likely
## 3887145426                                                                                                                              Somewhat likely
## 3887021873                                                                                                                                  Very likely
## 3886937140                                                                                                                              Somewhat likely
##                Age What.is.your.gender.
## 3887201482 30 - 44                 Male
## 3887159451 18 - 29                 Male
## 3887152228 30 - 44                 Male
## 3887145426 30 - 44                 Male
## 3887021873 30 - 44                 Male
## 3886937140 18 - 29                 Male
##            How.much.total.combined.money.did.all.members.of.your.HOUSEHOLD.earn.last.year.
## 3887201482                                                              $50,000 to $74,999
## 3887159451                                                            Prefer not to answer
## 3887152228                                                            $100,000 to $124,999
## 3887145426                                                            Prefer not to answer
## 3887021873                                                            $150,000 to $174,999
## 3886937140                                                            $100,000 to $124,999
##                     US.Region
## 3887201482     South Atlantic
## 3887159451                  -
## 3887152228    Middle Atlantic
## 3887145426                  -
## 3887021873    Middle Atlantic
## 3886937140 West South Central

When I first run the summary function on the dataframe I realized that all the variables are of type character. I need to change that. While I change the type I will change the variable names as well.

Starting with the first one “Do you typically check a daily weather report?”

weather$check_weather_daily <- as.factor(weather$Do.you.typically.check.a.daily.weather.report.)

And four other variables that need the same formating.

weather$check_weather_method <-as.factor(weather$How.do.you.typically.check.the.weather.)


weather$check_weather_from_smartwatch <-as.factor(weather$If.you.had.a.smartwatch..like.the.soon.to.be.released.Apple.Watch...how.likely.or.unlikely.would.you.be.to.check.the.weather.on.that.device.)

weather$gender <-as.factor(weather$What.is.your.gender.)

weather$US.Region <-as.factor(weather$US.Region)

summary(weather$US.Region)
##                  - East North Central East South Central    Middle Atlantic 
##                 31                141                 41                104 
##           Mountain        New England            Pacific     South Atlantic 
##                 72                 52                185                154 
## West North Central West South Central 
##                 54                 94

The data for the variables age and income need to be converted to ordered categorical.

unique(weather$Age)
## [1] "30 - 44" "18 - 29" "-"       "45 - 59" "60+"
# Replace "-" with NA

weather$Age[weather$Age == "-"] <- NA

#place the age groups in ascending ordered levels 
ordered_levels <- c("18 - 29", "30 - 44", "45 - 59", "60+", "NA")

weather$Age <- factor(weather$Age, levels = ordered_levels, ordered = TRUE) 

summary(weather$Age)
## 18 - 29 30 - 44 45 - 59     60+      NA    NA's 
##     176     204     278     258       0      12

Now I will follow the same approach for the income variable.

unique(weather$How.much.total.combined.money.did.all.members.of.your.HOUSEHOLD.earn.last.year.)
##  [1] "$50,000 to $74,999"   "Prefer not to answer" "$100,000 to $124,999"
##  [4] "$150,000 to $174,999" "$25,000 to $49,999"   "-"                   
##  [7] "$0 to $9,999"         "$10,000 to $24,999"   "$75,000 to $99,999"  
## [10] "$200,000 and up"      "$175,000 to $199,999" "$125,000 to $149,999"
weather$How.much.total.combined.money.did.all.members.of.your.HOUSEHOLD.earn.last.year.[weather$How.much.total.combined.money.did.all.members.of.your.HOUSEHOLD.earn.last.year.== "-"] <- NA

ordered_income_levels <- c("$0 to $9,999", "$10,000 to $24,999", "$25,000 to $49,999", "$50,000 to $74,999", "$75,000 to $99,999", "$100,000 to $124,999", "$125,000 to $149,999","$150,000 to $174,999","$175,000 to $199,999","Prefer not to answer", "NA" )

weather$income <- factor(weather$How.much.total.combined.money.did.all.members.of.your.HOUSEHOLD.earn.last.year., levels = ordered_income_levels, ordered = TRUE) 

summary(weather$income)
##         $0 to $9,999   $10,000 to $24,999   $25,000 to $49,999 
##                   45                   81                  132 
##   $50,000 to $74,999   $75,000 to $99,999 $100,000 to $124,999 
##                  111                  104                  104 
## $125,000 to $149,999 $150,000 to $174,999 $175,000 to $199,999 
##                   49                   39                   23 
## Prefer not to answer                   NA                 NA's 
##                  169                    0                   71
colnames(weather)
##  [1] "Do.you.typically.check.a.daily.weather.report."                                                                                              
##  [2] "How.do.you.typically.check.the.weather."                                                                                                     
##  [3] "A.specific.website.or.app..please.provide.the.answer."                                                                                       
##  [4] "If.you.had.a.smartwatch..like.the.soon.to.be.released.Apple.Watch...how.likely.or.unlikely.would.you.be.to.check.the.weather.on.that.device."
##  [5] "Age"                                                                                                                                         
##  [6] "What.is.your.gender."                                                                                                                        
##  [7] "How.much.total.combined.money.did.all.members.of.your.HOUSEHOLD.earn.last.year."                                                             
##  [8] "US.Region"                                                                                                                                   
##  [9] "check_weather_daily"                                                                                                                         
## [10] "check_weather_method"                                                                                                                        
## [11] "check_weather_from_smartwatch"                                                                                                               
## [12] "gender"                                                                                                                                      
## [13] "income"

Next, I will subset the dataset to include only my variables of interest.

weather_subset  <- na.omit(select(weather, "Age","check_weather_method", "check_weather_from_smartwatch", "check_weather_daily", "check_weather_method" ))

head(weather_subset)
##                Age                                  check_weather_method
## 3887201482 30 - 44                 The default weather app on your phone
## 3887159451 18 - 29                 The default weather app on your phone
## 3887152228 30 - 44                 The default weather app on your phone
## 3887145426 30 - 44                 The default weather app on your phone
## 3887021873 30 - 44 A specific website or app (please provide the answer)
## 3886937140 18 - 29 A specific website or app (please provide the answer)
##            check_weather_from_smartwatch check_weather_daily
## 3887201482                   Very likely                 Yes
## 3887159451                   Very likely                 Yes
## 3887152228                   Very likely                 Yes
## 3887145426               Somewhat likely                 Yes
## 3887021873                   Very likely                 Yes
## 3886937140               Somewhat likely                 Yes

I am interested to look into the relationship between people’s prefered method to check the weather and their age.

#Cross tabulation between my two variables of interest 
table(weather_subset$Age, weather_subset$check_weather_method)
##          
##            - A specific website or app (please provide the answer)
##   18 - 29  0                                                    28
##   30 - 44  0                                                    45
##   45 - 59  0                                                    57
##   60+      0                                                    45
##   NA       0                                                     0
##          
##           Internet search Local TV News Newsletter Newspaper Radio weather
##   18 - 29              35            14          2         2             5
##   30 - 44              26            34          1         1             6
##   45 - 59              33            67          2        13             6
##   60+                  36            74          3        16            14
##   NA                    0             0          0         0             0
##          
##           The default weather app on your phone The Weather Channel
##   18 - 29                                    64                  26
##   30 - 44                                    63                  28
##   45 - 59                                    51                  49
##   60+                                        35                  35
##   NA                                          0                   0

Visualize the relationship

ggplot(weather_subset, aes(x = Age, fill = check_weather_method)) +
  geom_bar(position = "fill") +
  ggtitle("Preferred Method to Check Weather by Age Group") +
  xlab("Age Group") +
  ylab("Count") 

Conclusion

Relationship between preferred method to check weather and age

Visually speaking, the first thing I notice is that there seems to be a negative correlation between age group and the use of the default weather app on someone’s phone to check the weather. Meaning younger age groups tend to use the default weather app more than older age groups. The opposite happens with using Local TV News, where older age groups have significantly higher rates of using it to check the weather than younger age groups.