sensor_data <- read.csv("/Users/manojdannana/Desktop/Manoj/IUPUI/class work/intro to statistics/datasets/Occupancy_Estimation.csv")
selected_columns <- sensor_data[, c("S1_Temp", "S2_Temp", "S3_Temp", "S4_Temp")]
sensor_data$Avg_Temp <- rowMeans(selected_columns)
sensor_data$Min_Temp <- apply(selected_columns, 1, min)
sensor_data$Max_Temp <- apply(selected_columns, 1, max)
head(sensor_data)
## Date Time S1_Temp S2_Temp S3_Temp S4_Temp S1_Light S2_Light S3_Light
## 1 22/12/17 10:49:41 24.94 24.75 24.56 25.38 121 34 53
## 2 22/12/17 10:50:12 24.94 24.75 24.56 25.44 121 33 53
## 3 22/12/17 10:50:42 25.00 24.75 24.50 25.44 121 34 53
## 4 22/12/17 10:51:13 25.00 24.75 24.56 25.44 121 34 53
## 5 22/12/17 10:51:44 25.00 24.75 24.56 25.44 121 34 54
## 6 22/12/17 10:52:14 25.00 24.81 24.56 25.44 121 34 54
## S4_Light S1_Sound S2_Sound S3_Sound S4_Sound S5_CO2 S5_CO2_Slope S6_PIR
## 1 40 0.08 0.19 0.06 0.06 390 0.7692308 0
## 2 40 0.93 0.05 0.06 0.06 390 0.6461538 0
## 3 40 0.43 0.11 0.08 0.06 390 0.5192308 0
## 4 40 0.41 0.10 0.10 0.09 390 0.3884615 0
## 5 40 0.18 0.06 0.06 0.06 390 0.2538462 0
## 6 40 0.13 0.06 0.06 0.07 390 0.1653846 0
## S7_PIR Room_Occupancy_Count Avg_Temp Min_Temp Max_Temp
## 1 0 1 24.9075 24.56 25.38
## 2 0 1 24.9225 24.56 25.44
## 3 0 1 24.9225 24.50 25.44
## 4 0 1 24.9375 24.56 25.44
## 5 0 1 24.9375 24.56 25.44
## 6 0 1 24.9525 24.56 25.44
library(ggplot2)
# Plot 1: S1_Temp vs Min_Temp
plot1 <- ggplot(sensor_data, aes(x = S1_Temp, y = Min_Temp)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) + # Add linear regression line
labs(title = "S1_Temp vs Min_Temp",
x = "S1_Temp",
y = "Min_Temp")
# Plot 2: S2_Temp vs Max_Temp
plot2 <- ggplot(sensor_data, aes(x = S2_Temp, y = Max_Temp)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) + # Add linear regression line
labs(title = "S2_Temp vs Max_Temp",
x = "S2_Temp",
y = "Max_Temp")
# Plot 3: Avg_Temp vs Room_Occupancy_Count
plot3 <- ggplot(sensor_data, aes(x = Avg_Temp, y = Room_Occupancy_Count)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) + # Add linear regression line
labs(title = "Avg_Temp vs Room_Occupancy_Count",
x = "Avg_Temp",
y = "Room_Occupancy_Count")
# Print the plots
print(plot1)
## `geom_smooth()` using formula = 'y ~ x'
print(plot2)
## `geom_smooth()` using formula = 'y ~ x'
print(plot3)
## `geom_smooth()` using formula = 'y ~ x'
cor_1 <- cor(sensor_data$S1_Temp, sensor_data$Min_Temp)
cor_2 <- cor(sensor_data$S2_Temp, sensor_data$Max_Temp)
cor_3 <- cor(sensor_data$Avg_Temp, sensor_data$Room_Occupancy_Count)
print(paste("Correlation coefficient for Min_Temp and S1_Temp:", cor_1))
## [1] "Correlation coefficient for Min_Temp and S1_Temp: 0.948652956061729"
print(paste("Correlation coefficient for S2_Temp and Max_temp:", cor_2))
## [1] "Correlation coefficient for S2_Temp and Max_temp: 0.932419308632456"
print(paste("Correlation coefficient for Avg_Temp and Room_Occupancy_Count:", cor_3))
## [1] "Correlation coefficient for Avg_Temp and Room_Occupancy_Count: 0.692697970884694"
The inferences that I made in the previous cell while plotting are correct as the correlation coefficient solidifies my inferences.
sample_mean <- mean(sensor_data$Min_Temp)
sample_sd <- sd(sensor_data$Min_Temp)
n <- length(sensor_data$Min_Temp)
confidence_level <- 0.95
critical_value <- qnorm((1 + confidence_level) / 2)
margin_of_error <- critical_value * (sample_sd / sqrt(n))
lower_bound <- sample_mean - margin_of_error
upper_bound <- sample_mean + margin_of_error
cat("Confidence interval for Min_Temp: (", lower_bound, ", ", upper_bound, ")\n")
## Confidence interval for Min_Temp: ( 25.04801 , 25.06463 )
sample_mean <- mean(sensor_data$Max_Temp)
sample_sd <- sd(sensor_data$Max_Temp)
n <- length(sensor_data$Max_Temp)
confidence_level <- 0.95
critical_value <- qnorm((1 + confidence_level) / 2)
margin_of_error <- critical_value * (sample_sd / sqrt(n))
lower_bound <- sample_mean - margin_of_error
upper_bound <- sample_mean + margin_of_error
cat("Confidence interval for Max_Temp: (", lower_bound, ", ", upper_bound, ")\n")
## Confidence interval for Max_Temp: ( 25.82284 , 25.84366 )
sample_mean <- mean(sensor_data$Room_Occupancy_Count)
sample_sd <- sd(sensor_data$Room_Occupancy_Count)
n <- length(sensor_data$Room_Occupancy_Count)
confidence_level <- 0.95
critical_value <- qnorm((1 + confidence_level) / 2)
margin_of_error <- critical_value * (sample_sd / sqrt(n))
lower_bound <- sample_mean - margin_of_error
upper_bound <- sample_mean + margin_of_error
cat("Confidence interval for Room_Occupancy_Count: (", lower_bound, ", ", upper_bound, ")\n")
## Confidence interval for Room_Occupancy_Count: ( 0.3811556 , 0.4159616 )