-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.R
More file actions
205 lines (141 loc) · 5.72 KB
/
script.R
File metadata and controls
205 lines (141 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
bodyPerformance <- read.csv("C:/Users/Mrinal/Downloads/bodyPerformance.csv")
data=bodyPerformance
#Visualising Data
num_cols <- unlist(lapply(data, is.numeric)) # Identify numeric columns
num_cols
data_num <- data[ , num_cols] # Subset numeric columns of data
data_num
colnames(data_num)=c('Age','Height (cm)','Weight (kg)','Body fat(%)','Diastolic','Systolic','Grip force','Sit and bend foreward(cm)','Sit up counts','Broad jump(cm)') # Changing column names
boxplot(data_num,col = factor(data_num$age),main='Boxplot') # Boxplot of numerical columns
#descriptive
summary(data$age,data$height_cm)
hist(data$age,main='',xlab = 'Age',col = "lightblue",border = "red",breaks = 20)
grid(nx = NA, ny = NULL, lty = 2, col = "gray", lwd = 1)
# count no of male & femalae
male_count <- sum(data$gender == "M")
female_count <- sum(data$gender == "F")
bar_data <- data.frame(
Gender = c("Male", "Female"),
Count = c(male_count, female_count)
)
barplot(bar_data$Count, names.arg = bar_data$Gender, col = c("blue", "pink"), main = "", xlab = "Gender", ylab = "Frequency")
legend("topright", legend = c("Male", "Female"), fill = c("blue", "pink"))
hist(data$height_cm,main='Histogram on Height',xlab = 'Height',col = "lightblue",border = "red",breaks = 20)
hist(data$weight_kg,main='Histogram on Weight',xlab = 'Weight',col = "lightblue",border = "red",breaks = 20)
hist(data$body.fat_.,main='Histogram on Body fat',xlab = 'Body fat',col = "lightblue",border = "red",breaks = 20)
hist(data$diastolic,main='Histogram on Diastolic',xlab = 'Diastolic',col = "lightblue",border = "red",breaks = 20)
hist(data$systolic,main='Histogram on Systolic',xlab = 'Systolic',col = "lightblue",border = "red",breaks = 20)
hist(data$gripForce,main='Histogram on gripForce',xlab = 'gripForce',col = "lightblue",border = "red",breaks = 20)
hist(data$sit.and.bend.forward_cm,main='Histogram on sit.and.bend.forward',xlab = 'sit.and.bend.forward',col = "lightblue",border = "red",breaks = 20)
hist(data$sit.ups.counts,main='Histogram on Sit ups counts',xlab = 'sit.ups.counts',col = "lightblue",border = "red",breaks = 20)
hist(data$broad.jump_cm,main='Histogram on broad.jump',xlab = 'broad.jump',col = "lightblue",border = "red",breaks = 20)
## Age vs Height cm
hist(data$age,data$height_cm)
hist(data$age, main = "Age vs Height", xlab = "Age", ylab = "Frequency", col = "lightblue", border = "black")
hist(data$height, col = "lightgreen", border = "black", add = TRUE, breaks = seq(150, 200, by = 100))
## correlation matrix
library(ggplot2)
library(ggcorrplot)
# Reading the data
q=data(USArrests)
# Computing correlation matrix
correlation_matrix <- round(cor(data_num),2)
# Computing correlation matrix with p-values
corrp.mat <- cor_pmat(USArrests)
# Adding the correlation coefficient
ggcorrplot(correlation_matrix, hc.order =TRUE,
type ="lower", lab =TRUE)
# Body fat vs gender
# Separate data for male and female
# Separate data for male and female
male_data <- data[data$gender == "M", ]
female_data <- data[data$gender == "F", ]
# Calculate average fat percentage for male and female
mean(data$body.fat_.)
max(data$body.fat_.)
min(data$body.fat_.)
mean(male_data$body.fat_.)
mean(female_data$body.fat_.)
hist(female_data$body.fat_., col = c("blue", "red", "gray", "green"))
hist(male_data$body.fat_.)
# gripForce
hist(data$gripForce, col = c("blue", "red", "gray", "green"),breaks = 30)
# sit.and.bend.forward_cm
hist(data$sit.and.bend.forward_cm, col = c("blue", "red", "gray", "green"),breaks = 50)
# sit.ups.counts
hist(data$sit.ups.counts, col = c("blue", "red", "gray", "green"),breaks = 30)
# broad.jump_cm
hist(data$broad.jump_cm, col = c("blue", "red", "gray", "green"),breaks = 20)
# Groupping ABCD
A_count <- sum(data$class == "A")
B_count <- sum(data$class == "B")
C_count <- sum(data$class == "C")
D_count <- sum(data$class == "D")
x <- c(A_count,B_count,C_count,D_count)
labels <- c("A", "B", "C", "D")
pie(x,labels)
# Classify ABCD group
class_A_data <- data[data$class == "A", ]
class_B_data <- data[data$class == "B", ]
class_C_data <- data[data$class == "C", ]
class_D_data <- data[data$class == "D", ]
# Summary of numerical values
summary(data_num)
View()
boxplot(data$systolic)
x=data$systolic
# get mean and Standard deviation
mean = mean(x)
std = sd(x)
# get threshold values for outliers
Tmin = mean-(3*std)
Tmax = mean+(3*std)
# find outlier
x[which(x < Tmin | x > Tmax)]
# remove outlier
z=x[which(x > Tmin & x < Tmax)]
boxplot(z)
boxplot(data$age)
# Test
### Shaprio wiki
shapiro.test(male_data$body.fat_.)
shapiro.test(female_data$body.fat_.)
x=male_data$body.fat_.
y=female_data$body.fat_.
t.test(x,y) #T-test
# Combine data into a data frame
one_way_anova_data <- list(Male = x, Female = y)
Data <- data.frame(
Y=c(x,y),
Site =factor(rep(c("M", "F"), times=c(length(x), length(y))))
)
fm1 <- aov(Y~Site, data=Data)
anova(fm1)
##
# Load necessary libraries for correlation analysis
library(stats)
# Extract relevant columns
weight_kg <- data$weight_kg
height_cm <- data$height_cm
systolic_bp <- data$systolic
# Convert height from cm to m
height_m <- height_cm / 100
# Calculate BMI
bmi <- weight_kg / (height_m * height_m)
# Conduct correlation analysis
correlation <- cor(bmi, systolic_bp)
# Perform hypothesis test for correlation coefficient
correlation_p_value <- cor.test(bmi, systolic_bp)$p.value
##
# Extract relevant columns
situps_counts <- data$sit.ups.counts
fitness_class <- data$class
# Conduct ANOVA
anova_result <- aov(situps_counts ~ fitness_class, data=data)
# Perform post-hoc Tukey's test for multiple comparisons
posthoc_result <- TukeyHSD(anova_result)
# Output results
cat("ANOVA Results:\n")
print(summary(anova_result))
cat("Post-hoc Tukey's Test Results:\n")
print(posthoc_result)