Is there a correlation between the wages and years of education?
library(carData)
## Warning: package 'carData' was built under R version 4.3.2
mydata1 <- force(SLID)
head(mydata1)
## wages education age sex language
## 1 10.56 15.0 40 Male English
## 2 11.00 13.2 19 Male English
## 3 NA 16.0 49 Male Other
## 4 17.76 14.0 46 Male Other
## 5 NA 8.0 71 Male English
## 6 14.00 16.0 50 Female English
Removing values with NA
library(tidyr)
mydata2 <- drop_na(mydata1)
head(mydata2)
## wages education age sex language
## 1 10.56 15.0 40 Male English
## 2 11.00 13.2 19 Male English
## 4 17.76 14.0 46 Male Other
## 6 14.00 16.0 50 Female English
## 9 8.20 15.0 31 Male English
## 12 16.97 13.5 30 Female English
Unit of observation: A worker Sample Size: 7425
Variables:
wages: Composite hourly wage rate from all jobs.
education: Number of years of schooling.
age: in years.
sex: A factor with levels: Female, Male.
language: A factor with levels: English, French, Other
Source: The data are taken from the public-use dataset made available by Statistics Canada, and prepared by the Institute for Social Research, York University
summary(mydata2)
## wages education age sex language
## Min. : 2.30 Min. : 0.00 Min. :16.0 Female:2001 English:3244
## 1st Qu.: 9.25 1st Qu.:12.00 1st Qu.:28.0 Male :1986 French : 259
## Median :14.13 Median :13.00 Median :36.0 Other : 484
## Mean :15.54 Mean :13.34 Mean :37.1
## 3rd Qu.:19.72 3rd Qu.:15.10 3rd Qu.:46.0
## Max. :49.92 Max. :20.00 Max. :69.0
Wages mean: Based on this sample, Composite hourly wage rate from all jobs is $15.54
Maximum Education: Based on this sample, the maximum years of education for a worker is 20 years
Checking if there is a correlation between the wages and the years of education of a worker
library(ggplot2)
ggplot(mydata2, aes(x = education, y = wages)) +
geom_point()
The data appears to be linear
library(ggplot2)
ggplot(mydata2, aes(x = wages)) +
geom_histogram(binwidth = 5, colour="gray") +
ylab("Frequency")
library(rstatix)
## Warning: package 'rstatix' was built under R version 4.3.2
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
shapiro_test(mydata2$wages)
## # A tibble: 1 × 3
## variable statistic p.value
## <chr> <dbl> <dbl>
## 1 mydata2$wages 0.925 7.93e-41
H0: Wages are normally distributed
H1: Wages are not normally distributed
Based on the Shapiro WIlks Test we can reject H0(p<0.001) and say that the wages are not normally distributed
As a result, using the Spearman coefficient is more suitable, but we will do the analysis using both Pearson and Spearman coefficients.
cor(mydata2$education, mydata2$wages,
method = "pearson")
## [1] 0.3059187
The above value of 0.30 shows there is a weak positive linear correlation between the wages and years of education
cor.test(mydata2$education, mydata2$wages,
method = "pearson",
use = "complete.obs")
##
## Pearson's product-moment correlation
##
## data: mydata2$education and mydata2$wages
## t = 20.284, df = 3985, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2775121 0.3337909
## sample estimates:
## cor
## 0.3059187
H0: There is no correlation between the wages and the years of education
H1: There is a correlation between the wages and the years of education
At p<0.001, we can reject H0 and say there is a linear correlation between the wages and the years of education
Using the Spearman correlation coefficient because the data is not normally distributed:
cor(mydata2$education, mydata2$wages,
method = "spearman",
use = "complete.obs")
## [1] 0.283671
The Spearman coefficient shows there is a weak positive linear correlation between the wages and the years of education.
H0: There is no correlation between the wages and the years of education
H1: There is a correlation between the wages and the years of education
cor.test(mydata2$education, mydata2$wages,
method = "spearman",
exact = FALSE,
use = "complete.obs")
##
## Spearman's rank correlation rho
##
## data: mydata2$education and mydata2$wages
## S = 7566585712, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.283671
At p<0.001, we can reject H0 and say there is a linear correlation between the wages and the years of education
From Pearson and Spearman correlation coefficients we can say there is a weak linear correlation between the wages and the years of education.
Is there is a relationship between the gender and language used?
mydata2$languageF <- factor(mydata2$language,
levels = c("English", "French", "Other"),
labels = c("English", "French", "Other"))
mydata2$sexF <- factor(mydata2$sex,
levels = c("Male", "Female"),
labels = c("Male", "Female"))
results <- chisq.test(mydata2$sexF, mydata2$languageF,
correct = FALSE)
results
##
## Pearson's Chi-squared test
##
## data: mydata2$sexF and mydata2$languageF
## X-squared = 2.0202, df = 2, p-value = 0.3642
H0: There is no association between the sex and the language used
H1: There is an association between the sex and the language used
As p>0.05, we can not reject H0 and we can say that there is no association between sex and the language that is used.
addmargins(results$observed)
## mydata2$languageF
## mydata2$sexF English French Other Sum
## Male 1608 140 238 1986
## Female 1636 119 246 2001
## Sum 3244 259 484 3987
round(results$expected)
## mydata2$languageF
## mydata2$sexF English French Other
## Male 1616 129 241
## Female 1628 130 243
round(results$res, 2)
## mydata2$languageF
## mydata2$sexF English French Other
## Male -0.20 0.97 -0.20
## Female 0.20 -0.96 0.20
Since all residuals are less than 1.96, we can say that the deviations are not significant
There are more than expected males who use French and less than expected males who use English or Other.
There are more than expected females who use English and Other, and less than expected Females who use French.
addmargins(round(prop.table(results$observed), 3))
## mydata2$languageF
## mydata2$sexF English French Other Sum
## Male 0.403 0.035 0.060 0.498
## Female 0.410 0.030 0.062 0.502
## Sum 0.813 0.065 0.122 1.000
81.3% of all the workers speak English, 6.5% speak French and 12.2% speak Other languages.
addmargins(round(prop.table(results$observed, 1), 3), 2)
## mydata2$languageF
## mydata2$sexF English French Other Sum
## Male 0.810 0.070 0.120 1.000
## Female 0.818 0.059 0.123 1.000
81% of Males speak English, 7% speak French and 12% speak Other languages.
addmargins(round(prop.table(results$observed, 2), 3), 1)
## mydata2$languageF
## mydata2$sexF English French Other
## Male 0.496 0.541 0.492
## Female 0.504 0.459 0.508
## Sum 1.000 1.000 1.000
49.6% of English users are Male, and 50.4% are Female.
library(effectsize)
## Warning: package 'effectsize' was built under R version 4.3.2
##
## Attaching package: 'effectsize'
## The following objects are masked from 'package:rstatix':
##
## cohens_d, eta_squared
effectsize::cramers_v(mydata2$languageF, mydata2$sexF)
## Cramer's V (adj.) | 95% CI
## --------------------------------
## 2.22e-03 | [0.00, 1.00]
##
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.002)
## [1] "tiny"
## (Rules: funder2019)
fisher.test(mydata2$languageF, mydata2$sexF)
##
## Fisher's Exact Test for Count Data
##
## data: mydata2$languageF and mydata2$sexF
## p-value = 0.3643
## alternative hypothesis: two.sided
H0: Odds ratio = 1
H1: Odds ratio = 1
At p>0.05, we can not reject H0
Based on conducted analysis, we can say that there is no association between sex and language used.