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(readxl)
Data <- read_excel("D:/SY 21-22 Second Sem/STAT 50/Data.xlsx")
Data
library(dplyr)
Data%>%
group_by(`Course Taken`)%>%
summarise(Frequency = n(), `Mean Age` = mean(Age))
library(dplyr)
Data%>%
group_by(`Course Taken`)%>%
summarise(Frequency = n(), `Mean Intrinsic5` = mean(`In5`),
`Mean Extrinsic4` = mean(Ex4), `Mean TP3` = mean(TP3), `Mean CP2` = mean(CP2))
"1 for "Strongly Disagree"
"2" for "Disagree"
"3" for "Moderately Disagree"
"4" for "Neutral"
"5" for "Moderately Agree"
"6" for Agree
"7" for "Strongly Agree"
library(dplyr)
Data<-Data%>%
mutate(In1.1=recode(`In1`,
"1" = "Strongly Disagree", "2" = "Disagree","3" = "Moderately Disagree", "4" = "Neutral", "5" = "Moderately Agree", "6" = "Agree","7" = "Strongly Agree"))%>%
mutate(In1.2=recode(`In2`,
"1" = "Strongly Disagree", "2" = "Disagree","3" = "Moderately Disagree", "4" = "Neutral", "5" = "Moderately Agree", "6" = "Agree","7" = "Strongly Agree"))
a. HOw many observations in Variable In1 that are strongly agree at the same time moderately disagree in variable In2?
Answer: 0
b. HOw many observations in Variable In2 that are strongly agree at the same time Neutral in variable In1?
Answer: 3
library(gmodels)
Warning: package 'gmodels' was built under R version 4.1.3
Crosstable<-CrossTable(Data$In1.1, Data$In1.2)
Cell Contents
|-------------------------|
| N |
| Chi-square contribution |
| N / Row Total |
| N / Col Total |
| N / Table Total |
|-------------------------|
Total Observations in Table: 163
| Data$In1.2
Data$In1.1 | Agree | Disagree | Moderately Agree | Moderately Disagree | Neutral | Strongly Agree | Strongly Disagree | Row Total |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Agree | 26 | 0 | 2 | 0 | 0 | 9 | 0 | 37 |
| 11.254 | 0.681 | 7.263 | 1.135 | 2.497 | 0.213 | 0.454 | |
| 0.703 | 0.000 | 0.054 | 0.000 | 0.000 | 0.243 | 0.000 | 0.227 |
| 0.433 | 0.000 | 0.042 | 0.000 | 0.000 | 0.265 | 0.000 | |
| 0.160 | 0.000 | 0.012 | 0.000 | 0.000 | 0.055 | 0.000 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Disagree | 0 | 1 | 2 | 1 | 0 | 0 | 0 | 4 |
| 1.472 | 11.657 | 0.574 | 6.273 | 0.270 | 0.834 | 0.049 | |
| 0.000 | 0.250 | 0.500 | 0.250 | 0.000 | 0.000 | 0.000 | 0.025 |
| 0.000 | 0.333 | 0.042 | 0.200 | 0.000 | 0.000 | 0.000 | |
| 0.000 | 0.006 | 0.012 | 0.006 | 0.000 | 0.000 | 0.000 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Moderately Agree | 20 | 0 | 17 | 1 | 2 | 7 | 0 | 47 |
| 0.421 | 0.865 | 0.721 | 0.135 | 0.433 | 0.802 | 0.577 | |
| 0.426 | 0.000 | 0.362 | 0.021 | 0.043 | 0.149 | 0.000 | 0.288 |
| 0.333 | 0.000 | 0.354 | 0.200 | 0.182 | 0.206 | 0.000 | |
| 0.123 | 0.000 | 0.104 | 0.006 | 0.012 | 0.043 | 0.000 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Moderately Disagree | 0 | 0 | 4 | 1 | 0 | 1 | 0 | 6 |
| 2.209 | 0.110 | 2.822 | 3.617 | 0.405 | 0.051 | 0.074 | |
| 0.000 | 0.000 | 0.667 | 0.167 | 0.000 | 0.167 | 0.000 | 0.037 |
| 0.000 | 0.000 | 0.083 | 0.200 | 0.000 | 0.029 | 0.000 | |
| 0.000 | 0.000 | 0.025 | 0.006 | 0.000 | 0.006 | 0.000 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Neutral | 9 | 2 | 22 | 1 | 8 | 3 | 0 | 45 |
| 3.454 | 1.658 | 5.776 | 0.105 | 8.112 | 4.345 | 0.552 | |
| 0.200 | 0.044 | 0.489 | 0.022 | 0.178 | 0.067 | 0.000 | 0.276 |
| 0.150 | 0.667 | 0.458 | 0.200 | 0.727 | 0.088 | 0.000 | |
| 0.055 | 0.012 | 0.135 | 0.006 | 0.049 | 0.018 | 0.000 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Strongly Agree | 5 | 0 | 1 | 0 | 0 | 13 | 0 | 19 |
| 0.568 | 0.350 | 3.774 | 0.583 | 1.282 | 20.606 | 0.233 | |
| 0.263 | 0.000 | 0.053 | 0.000 | 0.000 | 0.684 | 0.000 | 0.117 |
| 0.083 | 0.000 | 0.021 | 0.000 | 0.000 | 0.382 | 0.000 | |
| 0.031 | 0.000 | 0.006 | 0.000 | 0.000 | 0.080 | 0.000 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Strongly Disagree | 0 | 0 | 0 | 1 | 1 | 1 | 2 | 5 |
| 1.840 | 0.092 | 1.472 | 4.673 | 1.301 | 0.002 | 61.261 | |
| 0.000 | 0.000 | 0.000 | 0.200 | 0.200 | 0.200 | 0.400 | 0.031 |
| 0.000 | 0.000 | 0.000 | 0.200 | 0.091 | 0.029 | 1.000 | |
| 0.000 | 0.000 | 0.000 | 0.006 | 0.006 | 0.006 | 0.012 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Column Total | 60 | 3 | 48 | 5 | 11 | 34 | 2 | 163 |
| 0.368 | 0.018 | 0.294 | 0.031 | 0.067 | 0.209 | 0.012 | |
--------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
Crosstable
$t
y
x Agree Disagree Moderately Agree Moderately Disagree
Agree 26 0 2 0
Disagree 0 1 2 1
Moderately Agree 20 0 17 1
Moderately Disagree 0 0 4 1
Neutral 9 2 22 1
Strongly Agree 5 0 1 0
Strongly Disagree 0 0 0 1
y
x Neutral Strongly Agree Strongly Disagree
Agree 0 9 0
Disagree 0 0 0
Moderately Agree 2 7 0
Moderately Disagree 0 1 0
Neutral 8 3 0
Strongly Agree 0 13 0
Strongly Disagree 1 1 2
$prop.row
y
x Agree Disagree Moderately Agree
Agree 0.70270270 0.00000000 0.05405405
Disagree 0.00000000 0.25000000 0.50000000
Moderately Agree 0.42553191 0.00000000 0.36170213
Moderately Disagree 0.00000000 0.00000000 0.66666667
Neutral 0.20000000 0.04444444 0.48888889
Strongly Agree 0.26315789 0.00000000 0.05263158
Strongly Disagree 0.00000000 0.00000000 0.00000000
y
x Moderately Disagree Neutral Strongly Agree
Agree 0.00000000 0.00000000 0.24324324
Disagree 0.25000000 0.00000000 0.00000000
Moderately Agree 0.02127660 0.04255319 0.14893617
Moderately Disagree 0.16666667 0.00000000 0.16666667
Neutral 0.02222222 0.17777778 0.06666667
Strongly Agree 0.00000000 0.00000000 0.68421053
Strongly Disagree 0.20000000 0.20000000 0.20000000
y
x Strongly Disagree
Agree 0.00000000
Disagree 0.00000000
Moderately Agree 0.00000000
Moderately Disagree 0.00000000
Neutral 0.00000000
Strongly Agree 0.00000000
Strongly Disagree 0.40000000
$prop.col
y
x Agree Disagree Moderately Agree
Agree 0.43333333 0.00000000 0.04166667
Disagree 0.00000000 0.33333333 0.04166667
Moderately Agree 0.33333333 0.00000000 0.35416667
Moderately Disagree 0.00000000 0.00000000 0.08333333
Neutral 0.15000000 0.66666667 0.45833333
Strongly Agree 0.08333333 0.00000000 0.02083333
Strongly Disagree 0.00000000 0.00000000 0.00000000
y
x Moderately Disagree Neutral Strongly Agree
Agree 0.00000000 0.00000000 0.26470588
Disagree 0.20000000 0.00000000 0.00000000
Moderately Agree 0.20000000 0.18181818 0.20588235
Moderately Disagree 0.20000000 0.00000000 0.02941176
Neutral 0.20000000 0.72727273 0.08823529
Strongly Agree 0.00000000 0.00000000 0.38235294
Strongly Disagree 0.20000000 0.09090909 0.02941176
y
x Strongly Disagree
Agree 0.00000000
Disagree 0.00000000
Moderately Agree 0.00000000
Moderately Disagree 0.00000000
Neutral 0.00000000
Strongly Agree 0.00000000
Strongly Disagree 1.00000000
$prop.tbl
y
x Agree Disagree Moderately Agree
Agree 0.159509202 0.000000000 0.012269939
Disagree 0.000000000 0.006134969 0.012269939
Moderately Agree 0.122699387 0.000000000 0.104294479
Moderately Disagree 0.000000000 0.000000000 0.024539877
Neutral 0.055214724 0.012269939 0.134969325
Strongly Agree 0.030674847 0.000000000 0.006134969
Strongly Disagree 0.000000000 0.000000000 0.000000000
y
x Moderately Disagree Neutral Strongly Agree
Agree 0.000000000 0.000000000 0.055214724
Disagree 0.006134969 0.000000000 0.000000000
Moderately Agree 0.006134969 0.012269939 0.042944785
Moderately Disagree 0.006134969 0.000000000 0.006134969
Neutral 0.006134969 0.049079755 0.018404908
Strongly Agree 0.000000000 0.000000000 0.079754601
Strongly Disagree 0.006134969 0.006134969 0.006134969
y
x Strongly Disagree
Agree 0.000000000
Disagree 0.000000000
Moderately Agree 0.000000000
Moderately Disagree 0.000000000
Neutral 0.000000000
Strongly Agree 0.000000000
Strongly Disagree 0.012269939
Data1<-Data%>%
filter(Age!=21)%>%
filter(Age!=22)%>%
mutate(Agegroup = ifelse(Age<21, "Less than 21 years old", "more than 22 years old"))
Data1
t.test(Data1$InAverage~Data1$Agegroup, var.equal = TRUE)
Two Sample t-test
data: Data1$InAverage by Data1$Agegroup
t = 1.4709, df = 25, p-value = 0.1538
alternative hypothesis: true difference in means between group Less than 21 years old and group more than 22 years old is not equal to 0
95 percent confidence interval:
-0.3030324 1.8173182
sample estimates:
mean in group Less than 21 years old mean in group more than 22 years old
4.957143 4.200000
As shown in the above, the p-value is 0.1538. This means that the variances of the two groups are equal.
shapiro.test(res_aov$residuals)
Shapiro-Wilk normality test
data: res_aov$residuals
W = 0.96551, p-value = 0.00044
library(car)
Warning: package 'car' was built under R version 4.1.3
Loading required package: carData
Warning: package 'carData' was built under R version 4.1.3
Attaching package: 'car'
The following object is masked from 'package:dplyr':
recode
leveneTest(InAverage ~ `Course Taken`, Data)
Warning in leveneTest.default(y = y, group = group, ...): group coerced to
factor.
library(tidyverse)# data manipulation and visualization
Warning: package 'tidyverse' was built under R version 4.1.3
-- Attaching packages --------------------------------------- tidyverse 1.3.1 --
v ggplot2 3.3.5 v purrr 0.3.4
v tibble 3.1.6 v stringr 1.4.0
v tidyr 1.2.0 v forcats 0.5.1
v readr 2.1.2
Warning: package 'ggplot2' was built under R version 4.1.3
Warning: package 'tibble' was built under R version 4.1.3
Warning: package 'tidyr' was built under R version 4.1.3
Warning: package 'readr' was built under R version 4.1.3
Warning: package 'forcats' was built under R version 4.1.3
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
x car::recode() masks dplyr::recode()
x purrr::some() masks car::some()
library(ggpubr)#creating easily publication ready plots
Warning: package 'ggpubr' was built under R version 4.1.3
library(rstatix)#pipe-friendly R functions for easy statistical analyses
Warning: package 'rstatix' was built under R version 4.1.3
Attaching package: 'rstatix'
The following object is masked from 'package:stats':
filter
res.kruskal <- Data %>% kruskal_test(InAverage~`Course Taken`)
res.kruskal
No significant difference among the different courses in terms of their InAverage.