Rcode
3. Descriptive Results and Findings
setwd("C:/001K12")
data <- [Link]("[Link]", stringsAsFactors = FALSE)
colnames(data)
data <- data[-46, ]
#Q1
year <- data$Q1
year_freq <- table(year)
year_freq
percentages <- round(100 * year_freq / sum(year_freq), 1)
labels <- paste(names(year_freq), "-", percentages, "%")
barplot(year_freq,
legend = labels,
main = "College year of Survey Participant",
#Q2
data$Q2 <- [Link](data$Q2)
hist(data$Q2,
main = "GPAs of survey participant",
xlab = "GPA",
col = "lightblue",
border = "white")
summary(data$Q2)
mean(data$Q2, [Link] = TRUE)
median(data$Q2, [Link] = TRUE)
sd(data$Q2, [Link] = TRUE)
#Q3
data$Q3 <- [Link](data$Q3)
hist(data$Q3,
main = "Histogram of Hours Use Per Day",
xlab = "Hours per Day",
col = "lightblue",
border = "white")
summary(data$Q3)
mean(data$Q3, [Link] = TRUE)
median(data$Q3, [Link] = TRUE)
sd(data$Q3, [Link] = TRUE)
#Q4
social_media <- data$Q4
social_media_freq <- table(social_media)
social_media_freq
percentages <- round(100 * social_media_freq / sum(social_media_freq), 1)
labels <- paste(names(social_media_freq), "-", percentages, "%")
pie(social_media_freq,
labels = labels,
col = c("skyblue", "lightgreen", "lightpink","orange","red"),
main = "Pie chart of social network usage")
#Q5
purpose <- data$Q5
purpose_freq <- table(purpose)
purpose_freq
percentages <- round(100 * purpose_freq / sum(purpose_freq), 1)
labels <- paste(names(purpose_freq), "-", percentages, "%")
pie(purpose_freq,
labels = labels,
col = c("skyblue", "lightgreen", "lightpink","orange","red"),
main = "Pie chart of primary purposes when using social network")
#Q6
maintain_relationship <- data$Q6
maintain_relationship_freq <- table(maintain_relationship)
maintain_relationship_freq
barplot(maintain_relationship_freq,
legend= names(maintain_relationship_freq),
col = c("skyblue", "lightgreen", "lightpink","orange","red"),
main = "How social media helps to maintain relationship",
ylab = "Frequency"
)
#Q7
expand_relationship <- data$Q7
expand_relationship_freq <- table(expand_relationship)
expand_relationship_freq
percentages <- round(100 * expand_relationship_freq / sum(expand_relationship_freq), 1)
labels <- paste(names(expand_relationship_freq), "-", percentages, "%")
pie(expand_relationship_freq,
labels = labels,
col = c("skyblue", "lightgreen", "lightpink","orange","red"),
main = "how using social network expands number of friendships")
legend("topright",
legend = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"),
fill = c("skyblue", "lightgreen", "lightpink","orange","red"))
summary(data$Q7)
mean(data$Q7, [Link] = TRUE)
median(data$Q7, [Link] = TRUE)
sd(data$Q7, [Link] = TRUE)
#Q8
feeling <- data$Q8
feeling_freq <- table(feeling)
feeling_freq
percentages <- round(100 * feeling_freq / sum(expand_relationship_freq), 1)
labels <- paste(names(feeling_freq), "-", percentages, "%")
barplot(feeling_freq,
col = c("skyblue", "lightgreen"),
legend = labels,
main = "Feeling left out after seeing friends hanging out without you",
#Q9
conflict <- data$Q9
conflict_freq <- table(conflict)
conflict_freq
percentages <- round(100 * conflict_freq / sum(conflict_freq), 1)
labels <- paste(names(conflict_freq), "-", percentages, "%")
pie2 <- pie(expand_relationship_freq,
labels = labels,
col = c("skyblue", "lightgreen", "lightpink","orange","red"),
main = "how using social network causes conflicts in friendships")
#Q10
quality <- data$Q10
quality_freq <- table(quality)
quality_freq
percentages <- round(100 * quality_freq / sum(quality_freq), 1)
labels <- paste(names(quality_freq), "-", percentages, "%")
pie1 <- pie(quality_freq,
labels = labels,
col = c("skyblue", "lightgreen", "lightpink","orange","red"),
main = "Relationship Quality is Improved by Social Media")
legend("topright",
legend = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"),
fill = c("skyblue", "lightgreen", "lightpink","orange","red"))
summary(data$Q10)
mean(data$Q10, [Link] = TRUE)
median(data$Q10, [Link] = TRUE)
sd(data$Q10, [Link] = TRUE)
4. Results and Findings of the Hypothesis Test
data <- [Link]("cityu_survey.[Link]")
t_test_result <- [Link](data$Q10, mu = 3)
print(t_test_result)
Routput
3. Descriptive Results and Findings
setwd("C:/001K12")
> data <- [Link]("[Link]", stringsAsFactors = FALSE)
> colnames(data)
[1] "Q1" "Q2" "Q3" "Q4" "Q5" "Q6" "Q7" "Q8" "Q9" "Q10"
>
> data <- data[-46, ]
> #Q1
> year <- data$Q1
> year_freq <- table(year)
> year_freq
year
Year 1 Year 2 Year 3 Year 4
8 75 9 7
>
> percentages <- round(100 * year_freq / sum(year_freq), 1)
>
>
> labels <- paste(names(year_freq), "-", percentages, "%")
>
>
> barplot(year_freq,
+ legend = labels,
+ main = "College year of Survey Participant",
+
+)
>
> #Q2
> data$Q2 <- [Link](data$Q2)
Warning message:
NAs introduced by coercion >
> hist(data$Q2,
+ main = "GPAs of survey participant",
+ xlab = "GPA",
+ col = "lightblue",
+ border = "white")
>
> summary(data$Q2)
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
3.000 7.425 8.000 7.402 8.165 10.000 1
>
>
> mean(data$Q2, [Link] = TRUE)
[1] 7.401531
>
>
> median(data$Q2, [Link] = TRUE)
[1] 8
>
>
> sd(data$Q2, [Link] = TRUE)
[1] 1.736838
>
> #Q3
>
> data$Q3 <- [Link](data$Q3)
Warning message:
NAs introduced by coercion >
> hist(data$Q3,
+ main = "Histogram of Hours Use Per Day",
+ xlab = "Hours per Day",
+ col = "lightblue",
+ border = "white")
>
> summary(data$Q3)
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
2.000 4.000 5.000 5.558 6.000 23.000 22
>
>
> mean(data$Q3, [Link] = TRUE)
[1] 5.558442
>
>
> median(data$Q3, [Link] = TRUE)
[1] 5
>
>
> sd(data$Q3, [Link] = TRUE)
[1] 2.793289
>
>
> #Q4
> social_media <- data$Q4
> social_media_freq <- table(social_media)
> social_media_freq
social_media
Facebook Instagram Threads Tiktok Youtube
25 22 2 44 6
>
>
> percentages <- round(100 * social_media_freq / sum(social_media_freq), 1)
>
>
> labels <- paste(names(social_media_freq), "-", percentages, "%")
>
>
> pie(social_media_freq,
+ labels = labels,
+ col = c("skyblue", "lightgreen", "lightpink","orange","red"),
+ main = "Pie chart of social network usage")
>
> #Q5
>
> purpose <- data$Q5
> purpose_freq <- table(purpose)
> purpose_freq
purpose
Communication Entertainment Learning Self-promotion
14 65 12 8
>
>
> percentages <- round(100 * purpose_freq / sum(purpose_freq), 1)
>
>
> labels <- paste(names(purpose_freq), "-", percentages, "%")
>
>
> pie(purpose_freq,
+ labels = labels,
+ col = c("skyblue", "lightgreen", "lightpink","orange","red"),
+ main = "Pie chart of primary purposes when using social network")
>
> #Q6
> maintain_relationship <- data$Q6
> maintain_relationship_freq <- table(maintain_relationship)
> maintain_relationship_freq
maintain_relationship
Follow updates and like posts Message regularly online Schedule meetups
through social apps
18 33 10
Share memes or content to stay in touch
38
>
>
> barplot(maintain_relationship_freq,
+ col = c("skyblue", "lightgreen", "lightpink","orange","red"),
+ main = "How social media helps to maintain relationship",
+ ylab = "Frequency"
+)
>
> legend("topleft",
+ legend = names(maintain_relationship_freq),
+ fill = c("skyblue", "lightgreen", "lightpink", "orange", "red"),
+ cex = 0.8 ) # Adjust text size
> #Q7
>
> expand_relationship <- data$Q7
> expand_relationship_freq <- table(expand_relationship)
> expand_relationship_freq
expand_relationship
1 2 3 4 5
7 3 28 38 23
>
>
> percentages <- round(100 * expand_relationship_freq / sum(expand_relationship_freq), 1)
>
>
> labels <- paste(names(expand_relationship_freq), "-", percentages, "%")
>
>
> pie(expand_relationship_freq,
+ labels = labels,
+ col = c("skyblue", "lightgreen", "lightpink","orange","red"),
+ main = "how using social network expands number of friendships")
>
>
> legend("topright",
+ legend = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"),
+ fill = c("skyblue", "lightgreen", "lightpink","orange","red"))
>
> summary(data$Q7)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.000 3.000 4.000 3.677 4.000 5.000
>
>
> mean(data$Q7, [Link] = TRUE)
[1] 3.676768
>
>
> median(data$Q7, [Link] = TRUE)
[1] 4
>
>
> sd(data$Q7, [Link] = TRUE)
[1] 1.086356
>
> #Q8
> feeling <- data$Q8
> feeling_freq <- table(feeling)
> feeling_freq
feeling
No Yes
56 43
>
> percentages <- round(100 * feeling_freq / sum(expand_relationship_freq), 1)
>
>
> labels <- paste(names(feeling_freq), "-", percentages, "%")
>
>
> barplot(feeling_freq,
+ col = c("skyblue", "lightgreen"),
+ legend = labels,
+ main = "Feeling left out after seeing friends hanging out without you",
+
+)
>
> #Q9
> conflict <- data$Q9
> conflict_freq <- table(conflict)
> conflict_freq
conflict
Never Often Rarely Sometimes Very often
11 12 25 46 5
>
>
> percentages <- round(100 * conflict_freq / sum(conflict_freq), 1)
>
>
> labels <- paste(names(conflict_freq), "-", percentages, "%")
>
>
> pie2 <- pie(expand_relationship_freq,
+ labels = labels,
+ col = c("skyblue", "lightgreen", "lightpink","orange","red"),
+ main = "how using social network causes conflicts in friendships")
>
> #Q10
> quality <- data$Q10
> quality_freq <- table(quality)
> quality_freq
quality
1 2 3 4 5
3 7 31 33 25
>
>
> percentages <- round(100 * quality_freq / sum(quality_freq), 1)
>
>
> labels <- paste(names(quality_freq), "-", percentages, "%")
>
>
> pie1 <- pie(quality_freq,
+ labels = labels,
+ col = c("skyblue", "lightgreen", "lightpink","orange","red"),
+ main = "Relationship Quality is Improved by Social Media")
>
>
> legend("topright",
+ legend = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"),
+ fill = c("skyblue", "lightgreen", "lightpink","orange","red"))
>
> summary(data$Q10)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.000 3.000 4.000 3.707 4.500 5.000
>
>
> mean(data$Q10, [Link] = TRUE)
[1] 3.707071
>
>
> median(data$Q10, [Link] = TRUE)
[1] 4
>
>
> sd(data$Q10, [Link] = TRUE)
[1] 1.022727
4.
One Sample t-test
data: data$Q10
t = 6.8627, df = 99, p-value = 2.796e-10
alternative hypothesis: true mean is not equal to 3
95 percent confidence interval:
3.490 3.910
sample estimates:
mean of x
3.70