sensor_data <- read.csv("/Users/manojdannana/Desktop/Manoj/IUPUI/class work/intro to statistics/datasets/Occupancy_Estimation.csv")

Creating 3 more columns from the existing columns

  1. Avg_Temp - The average temperature of temperatures calculated by all the 4 sensors (S1_Temp, S2_Temp, S3_Temp, S4_Temp)
  2. Min_Temp - The minimum temperature recorded between all the 4 sensors (S1_Temp, S2_Temp, S3_Temp, S4_Temp)
  3. Max_Temp - The maximum temperature recorded between all the 4 sensors (S1_Temp, S2_Temp, S3_Temp, S4_Temp)
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

Columns being considered for analysis:

  1. S1_Temp vs Min_Temp( here S1_Temp is the Explanatory Variable and Min_Temp is the Response Variable)
  2. S2_Temp vs Max_temp ( here S2_Temp is the Explanatory Variable and Max_temp is the Response Variable)
  3. Avg_Temp vs Room_Occupancy_Count ( here Avg_Temp is the Explanatory Variable and Room_Occupancy_Count is the Response Variable)
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'

Inferences:

  1. Min_Temp vs S1_Temp:
    • The data seems to have no particular noticeable outliers as most data points seem to lie in a in between a range.
    • There seems to be a positive correlation between S1_Temp and Min_Temp as most data points seem to lie closer to the regression lie. When S1_Temp increases there seems to be a increase in Min_Temp, hence the positive correlation.
    • Most data points seem to occur in intervals i.e; a group of data points lie in a certain intervals which makes it seem like there is some pattern to this distribution.
  2. S2_Temp vs Max_temp:
    • The data seems to have no outliers but the distribution seems irregular, hence it’s better to use different statistical methods like IQR, standard deviations etc to judge the outliers in this.
    • There definitely seems to be a positive correlation between S2_Temp and Max_Temp and most data points lie closer to the regression line. When S2_Temp increases there seems to be a increase in Max_Temp, hence the positive correlation.
    • Unlike the previous graph, in this graph the data points seem to lie group in a a range of 24.5 to 26.5 on X-Axis and after that the data points become very sparse. This might be an indication that there might be other factors that are influencing the Max_Temp which might cause this anomaly.
  3. Avg_Temp vs Room_Occupancy_Count:
    • The data seems to have no noticeable outliers as most data points seem to lie in a in between a range.
    • There definitely seems to be a positive correlation between Avg_Temp and Room_Occupancy_Count and most data points lie closer to the regression line. When Avg_Temp increases there seems to be a increase in Room_Occupancy_Count, hence the positive correlation.
    • As Y-Axis has integer values the distribution occurs only along a particular value of Y-Axis.
    • Most part of the graph seems normal but in case where Room_Occupancy_Count = 1 there seems to be a bit of an anomaly where there are no data points for a few small ranges of Avg_Temps, this could be further investigated.

Correlation Coefficients for all pairs

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"

Inferences:

The inferences that I made in the previous cell while plotting are correct as the correlation coefficient solidifies my inferences.

Confidence Levels for all response variables

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 )

Inferences:

  1. For the temperature variables (Min_Temp and Max_Temp), the small range of the intervals means we’re pretty sure about the average temperature. This likely means the temperature doesn’t change much.
  2. For Room_Occupancy_Count, the confidence interval shows the average number of people in the room, and the wider the range, the less sure we are about that average.