Assignment# 06
Assignment# 06
R Notebook
This is an R Markdown (http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the
results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and
pressing Ctrl+Shift+Enter.
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
Assignment-06
Exercise-75
Step-01:Load the data
students<-read.delim("E:\\Statistics\\Datasets\\Students.txt",
stringsAsFactors=F)
summary(students)
Conclusion
file:///E:/Statistics/Exercises/Assignment-06.html 2/16
11/29/24, 12:41 PM R Notebook
# As p<0.05, we reject the null hypothesis. There is sufficient evidence to conclude that body w
eight and body height are significantly positively linearly related with a correlation coefficie
nt of 𝑟=0.7790491.
library(ggpubr)
ggscatter(
students, x = "Weight_kg", y = "Size_cm",
color = "#1f77b4",
add = "reg.line",
conf.int = TRUE,
add.params = list(color = "#ff7f0e"),
cor.coef = TRUE, cor.method = "pearson",
xlab = "Weight (kg)", ylab = "Height (cm)"
)
file:///E:/Statistics/Exercises/Assignment-06.html 3/16
11/29/24, 12:41 PM R Notebook
Conclusion
#The scatter plot reveals a Strong positive linear relationship between coefficient of body weig
ht and body height in the data set students.
Step-05:Shapiro-Wilk tests
## W-statistic: 0.9195322
## p-value: 7.40539e-05
file:///E:/Statistics/Exercises/Assignment-06.html 4/16
11/29/24, 12:41 PM R Notebook
## W-statistic: 0.958204
## p-value: 0.009213035
Step-06:Q-Q Plots
library(ggpubr)
file:///E:/Statistics/Exercises/Assignment-06.html 5/16
11/29/24, 12:41 PM R Notebook
Conclusion
Exercise-76
Step 01:Load the data:
# View the structure of the data to identify the columns for negative and positive mood
str(ICM)
file:///E:/Statistics/Exercises/Assignment-06.html 6/16
11/29/24, 12:41 PM R Notebook
file:///E:/Statistics/Exercises/Assignment-06.html 7/16
11/29/24, 12:41 PM R Notebook
## [1] 5
sum(is.na(ICM$PositiveMood))
## [1] 3
Conclusion
print(cor_test)
##
## Pearson's product-moment correlation
##
## data: ICM_clean$NegativeMood and ICM_clean$PositiveMood
## t = -11.644, df = 192, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.7190609 -0.5525618
## sample estimates:
## cor
## -0.6433565
file:///E:/Statistics/Exercises/Assignment-06.html 8/16
11/29/24, 12:41 PM R Notebook
library(ggpubr)
ggscatter(
ICM_clean, x = "NegativeMood", y = "PositiveMood",
color = "#1f77b4",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Negative Mood", ylab = "Positive Mood"
)
Step-05:Shapiro-Wilk tests
print(shapiro_negative)
file:///E:/Statistics/Exercises/Assignment-06.html 9/16
11/29/24, 12:41 PM R Notebook
##
## Shapiro-Wilk normality test
##
## data: ICM_clean$NegativeMood
## W = 0.97664, p-value = 0.002498
print(shapiro_positive)
##
## Shapiro-Wilk normality test
##
## data: ICM_clean$PositiveMood
## W = 0.98441, p-value = 0.03015
Step-06:Q-Q Plot
file:///E:/Statistics/Exercises/Assignment-06.html 10/16
11/29/24, 12:41 PM R Notebook
file:///E:/Statistics/Exercises/Assignment-06.html 11/16
11/29/24, 12:41 PM R Notebook
Conclusion
# Shapiro-Wilk Test for Negative Mood: As p<0.05 , W = 0.97664, p-value = 0.002498,we reject the
null hypothesis. The data for Negative Mood is not normally distributed.
# Shapiro-Wilk Test for Positive Mood: As p<0.05 , W = 0.98441, p-value = 0.03015,we reject the
null hypothesis. The data for Positive Mood is not normally distributed.
Exercise-79
Step-01:Load the Dataset
# View the structure of the dataset to identify the columns for weight and height
str(students)
file:///E:/Statistics/Exercises/Assignment-06.html 12/16
11/29/24, 12:41 PM R Notebook
# View the first few rows of the dataset to check the data
head(students)
1 24 M 0 0 0 + 1 no
2 5 M 0 0 0 + 1 no
3 54 F 1 A 1 + 1 no
4 9 M 0 0 0 + 1 no
5 34 F 1 A 1 + 1 no
6 52 F 1 0 0 + 1 ye
# Calculate Spearman's rank correlation coefficient between body weight and body height
spearman_corr <- cor(students$Weight_kg, students$Size_cm, method = "spearman")
file:///E:/Statistics/Exercises/Assignment-06.html 13/16
11/29/24, 12:41 PM R Notebook
print(cor_test)
##
## Spearman's rank correlation rho
##
## data: students$Weight_kg and students$Size_cm
## S = 20764, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.7740172
Conclusion
#S = 20764, p-value < 2.2e-16,as the p-value is less than 0.05, we reject the null hypothesis. T
herefore, we conclude that there is a statistically significant monotonic relationship between b
ody weight and body height with a Spearman’s rho of p=0.7740172.
Exercise-80
Step-01:Load and view the Dataset
# View the structure of the data to identify the columns for NegativeMood and OHS
str(ICM)
file:///E:/Statistics/Exercises/Assignment-06.html 14/16
11/29/24, 12:41 PM R Notebook
# View the first few rows of the dataset to check the data
head(ICM)
file:///E:/Statistics/Exercises/Assignment-06.html 15/16
11/29/24, 12:41 PM R Notebook
print(cor_test)
##
## Spearman's rank correlation rho
##
## data: ICM$NegativeMood and ICM$OHS
## S = 1453320, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.5725575
Conclusion
#S = 1453320, p-value < 2.2e-16,as the p-value is less than 0.05, we reject the null hypothesis
and conclude that there is a statistically significant negative monotonic relationship between n
egative mood and OHS.
file:///E:/Statistics/Exercises/Assignment-06.html 16/16