.

Age related differences in working hours solution

Analysis

Calculation of self-reported work hours differ between male and female full-time workers on average in Sydney after correcting for age can be done by: 1. Calculate average work hours male and female based on their ages 2. Calculate of the difference average work hours between male and female 3. Performing linier regression to generate general formula between difference work and age

step 1 : Calculate average work hours male and female based on their ages

#age in workhours
workhours <- read.csv(file = "workhours.csv")
factor_age <- factor(workhours$age)
age <- as.numeric(levels(factor_age))

#average male works hours basen on their age
average_male_hours <- vector(mode = "numeric", length = length(age))
for (i in 1:length(age)){
  average_male_hours[i]  <- mean(subset(workhours, sex == "male" & age == age[i], select = c(work))[[1]])
}

#average female works hours basen on their age
average_female_hours <- vector(mode = "numeric", length = length(age))
for (i in 1:length(age)){
  average_female_hours[i]  <- mean(subset(workhours, sex == "female" & age == age[i], select = c(work))[[1]])
}

#create new dataframe
new_workhours <- data.frame(Age = age, workhours_male_avg = average_male_hours, workhours_female_avg = average_female_hours)

step 2: Calculate of the difference average work hours between male and female

#calculate difference between average male and female workhours
new_workhours$workhours_difference = new_workhours$workhours_male_avg - new_workhours$workhours_female_avg

step 3: Performing linier regression to generate general formula between difference work and age

linier regression can easily be done by performing lm() function

linier_regression <- lm(formula = age ~ workhours_difference, data = new_workhours)
summary(linier_regression)

##
## Call:
## lm(formula = age ~ workhours_difference, data = new_workhours)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -23.952 -11.899  -1.938  11.112  25.986
##
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)   
## (Intercept)           44.6560     4.0687  10.976 1.94e-14 ***
## workhours_difference  -0.5878     0.6572  -0.894    0.376   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.03 on 46 degrees of freedom
## Multiple R-squared:  0.01709,    Adjusted R-squared:  -0.004277
## F-statistic: 0.7998 on 1 and 46 DF,  p-value: 0.3758

plot(new_workhours$Age, new_workhours$workhours_difference, ylab = "work", xlab = "age", main = "Difference self reported work hours between male and female \nfulltime workers on  average in Sydney")

statistics-assignment-solution-2-img1

Based on, linier regresion, it can be concluded that difference self reported working hours between male and female in sydney = 44.65 hours - 0.5878 x age. In other words, the difference decrease for older workers than younger ones.

Further analysis of p-value showed that the differnce work hours doesn’t depend on age because p-value > 0.005.

.