Data

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:/Winelyn/Data.xlsx")
View(Data)
library(rmarkdown)
paged_table(Data)

Answer as indicated

1. Provide the same output provided below

1.1 First output:

Data1<-Data%>%
  group_by(`Course Taken`)%>%
  summarise(Frequency=n(), 'Mean Age' = mean(Age))
paged_table(Data1)

1.2 Second output:

Consider the variables: In5, Ex4, TP3, and CP2

Data2<-Data%>%
  group_by(`Course Taken`)%>%
  summarise(Frequency=n(), 'Mean Intrinsic5' = mean(In5), 'Mean Extrinsic4' = mean(Ex4), 'Mean TP3' = mean(TP3), 'Mean CP2' = mean(CP2))
paged_table(Data2)

Recoding the responses in Variables “In1 and In2” with the following changes

"1" for "Strongly Disagree"
"2" for "Disagree"
"3" for "Moderately Disagree"
"4" for "Neutral"
"5" for "Agree"
"6" for "Strongly Agree"
Data3<-Data%>%
  mutate(In1.1=recode(`In1`, 
                          "1" = "Strongly Disagree", "2" ="Disagree", "3" = "Moderately Disagree", "4" = "Neutral", "5"="Agree", "6" = "Strongly Agree"))%>%
  mutate(In2.1=recode(`In2`, 
                          "1" = "Strongly Disagree", "2" ="Disagree", "3" = "Moderately Disagree", "4" = "Neutral", "5"="Agree", "6" = "Strongly Agree"))
## Warning: Unreplaced values treated as NA as `.x` is not compatible.
## Unreplaced values treated as NA as `.x` is not compatible.
## Please specify replacements exhaustively or supply `.default`.
paged_table(Data3)

2.1 Answer the following:

    a. HOw many observations in Variable In1 that are strongly agree at the same time moderately disagree in variable In2?
    Answer: There is no observations in Variable In1 that are strongly agree at the same time moderately disagree in variable In2.
    
    b. HOw many observations in Variable In2 that are strongly agree at the same time Neutral in variable In1?
    Answer: There are 9 observations in Variable In2 that are strongly agree at the same time Neutral in variable In1.
 

3. Consider the following:

Make a new variable named as “InAverage”, InAverage is the average of the responses in the variables In1, In2, IIn3, In4, and In5.

Make two groups of the variable “Age”,

Grouping:

Data$In1=as.numeric(Data$In1)
Data$In2=as.numeric(Data$In2)
Data$In3=as.numeric(Data$In3)
Data$In4=as.numeric(Data$In4)
Data$In5=as.numeric(Data$In5)
Data$InAverage<-(Data$In1+Data$In2+Data$In3+Data$In4+Data$In5)/5

Group 1 with age less than 21 years old

Data<-Data%>%
 mutate(`InAverage` = ifelse(InAverage<=14,"Low InAverage", 
                   ifelse(InAverage>=25, "High InAverage", "Normal")))%>%
 mutate(`Group 1` = ifelse(Age<=21, "less than 21 years old", "at least 21 years old"))
Data4<-Data%>%
  group_by(`Group 1`, `InAverage`) %>%
  summarise(count=n())%>%
  mutate(Percentage =count/sum(count))
## `summarise()` has grouped output by 'Group 1'. You can override using the
## `.groups` argument.
paged_table(Data4)

Group 2 with age more than 22 years old

Data<-Data%>%
 mutate(`InAverage` = ifelse(InAverage<=14,"Low InAverage", 
                   ifelse(InAverage>=25, "High InAverage", "Normal")))%>%
 mutate(`Group 2` = ifelse(Age>=22, "more than 22 years old", "at most 22 years old"))
Data5<-Data%>%
  group_by(`Group 2`, `InAverage`) %>%
  summarise(count=n())%>%
  mutate(Percentage =count/sum(count))
## `summarise()` has grouped output by 'Group 2'. You can override using the
## `.groups` argument.
paged_table(Data5)

3.1 Is there a significant difference between the two groups of age in terms of the variable “InAverage”?

table2=matrix(c(91,72, 72, 91) ,ncol=2) 
colnames(table2)=c("Group 1", "Group 2") 
rownames(table2)=c("less than 21 years old", "more than 22 years old")
table2
##                        Group 1 Group 2
## less than 21 years old      91      72
## more than 22 years old      72      91
chisq.test(table2)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  table2
## X-squared = 3.9755, df = 1, p-value = 0.04617

Interpretation

      The result shows that the InAverage between Group 1 and Group 2 does statistically differ since the p-value = 0.04617 does not exceeds the 0.05 level of significance.

4. Is there a significant difference among the courses taken in terms of the variable “InAverage”?

res.ftest <- variable.names(Data$InAverage~Data$`Course Taken`)
res.ftest
## NULL

Interpretation

      There is no significant difference among the courses taken in terms of the variable "InAverage".