---
title: "Week2_assignment_manoj"
output: html_document
---
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data <- read.csv("/Users/manojdannana/Desktop/Manoj/IUPUI/class work/intro to statistics/datasets/Occupancy_Estimation.csv")
print("---Numerical Columns---")
## [1] "---Numerical Columns---"
cat("Summary for S1_Temp: ")
## Summary for S1_Temp:
print(summary(data$S1_Temp))
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   24.94   25.19   25.38   25.45   25.63   26.38
cat("Summary for S2_Temp: ")
## Summary for S2_Temp:
print(summary(data$S2_Temp))
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   24.75   25.19   25.38   25.55   25.63   29.00
#convert the data types for categorical columns
data$S6_PIR <- as.character(data$S6_PIR)
data$S7_PIR <- as.character(data$S7_PIR)

print("---Categorical Columns---")
## [1] "---Categorical Columns---"
cat("About S6_PIR")
## About S6_PIR
cat("Unique values in S6_PIR")
## Unique values in S6_PIR
uniq <- unique(data$S6_PIR)
print(uniq)
## [1] "0" "1"
cat("Counts of values in S6_PIR")
## Counts of values in S6_PIR
for (variable in uniq) {
  cat("Count of ", variable, " in S6_PIR is \n")
  print(sum(data$S6_PIR == variable))
}
## Count of  0  in S6_PIR is 
## [1] 9216
## Count of  1  in S6_PIR is 
## [1] 913
cat("About S7_PIR")
## About S7_PIR
cat("Unique values in S7_PIR")
## Unique values in S7_PIR
uniq <- unique(data$S7_PIR)
print(uniq)
## [1] "0" "1"
cat("Counts of values in S7_PIR")
## Counts of values in S7_PIR
for (variable in uniq) {
  cat("Count of ", variable, " in S7_PIR is \n")
  print(sum(data$S7_PIR == variable))
}
## Count of  0  in S7_PIR is 
## [1] 9323
## Count of  1  in S7_PIR is 
## [1] 806

Insights

  1. Both S6_PIR and S7_PIR have a lot of negatives (0’s) than positives (1’s).

  2. Both S_Temp and S2_Temp data distribution seems to be well knit in a very small range as all 3 quartiles are close to each other and the min and max values.

Hypothesis/Questions

  1. Does the temperature play an important role in the occupancy of the room? i.e; if the room temperature is high then the room occupancy is high and vice verse. Reg col S1_Temp
  2. Is the Room occupancy affected by the illumination of the room? i.e; More the illumination, more is the occupancy and vice verse. Reg col S1_Light
  3. Do the CO2 levels of a room indicate bad ventilation? i.e; this might affect the occupancy of the room. More CO2 levels might indicate less room occupancy and vice verse. Reg col S5_CO2

Aggregate Functions for Hypothesis/Question 1:

Insights

Mean of Room Occupancy at a particular temperature level, from the eye test we can see that as the room temperature increases the room occupancy probably increases

temperature_counts <- aggregate(Room_Occupancy_Count ~ S1_Temp, data = data, FUN = mean)
sorted_by <- temperature_counts[order(-temperature_counts$Room_Occupancy_Count), ]
print(sorted_by)
##    S1_Temp Room_Occupancy_Count
## 24   26.38          3.000000000
## 23   26.31          2.755244755
## 22   26.25          2.555970149
## 21   26.19          2.003731343
## 20   26.13          1.670520231
## 17   25.94          1.229452055
## 19   26.06          1.150862069
## 1    24.94          1.000000000
## 15   25.81          0.987704918
## 14   25.75          0.975757576
## 18   26.00          0.943005181
## 13   25.69          0.823008850
## 16   25.88          0.796536797
## 11   25.56          0.581300813
## 12   25.63          0.521739130
## 10   25.50          0.273037543
## 2    25.00          0.064000000
## 9    25.44          0.038869258
## 8    25.38          0.034179688
## 6    25.25          0.027027027
## 7    25.31          0.020930233
## 5    25.19          0.016245487
## 3    25.06          0.011055276
## 4    25.13          0.009183673

Visual Summaries

S1_Temp and Room_Occupancy_Count

data$Date <- as.Date(data$Date, format = "%d/%m/%y")

barplot(table(data$S1_Temp, data$Room_Occupancy_Count), main = "Bar Plot: Room_Occupancy_Count by S1_Temp", xlab = "S1_Temp", ylab = "Count", col = rainbow(5))

ggplot(data, aes(x = S1_Temp, y = Room_Occupancy_Count, color = as.factor(Room_Occupancy_Count))) +
  geom_point() +
  labs(title = "Scatter Plot: S1_Temp vs. Room_Occupancy_Count",
       x = "S1_Temp", y = "Room_Occupancy_Count") +
  scale_color_discrete(name = "Room_Occupancy_Count")

ggplot(data, aes(x = S6_PIR, y = Room_Occupancy_Count)) +
  geom_point(aes(color = as.factor(Room_Occupancy_Count))) +
  labs(title = "Scatter Plot: S6_PIR vs. Room_Occupancy_Count",
       x = "S6_PIR", y = "Room_Occupancy_Count") +
  scale_color_discrete(name = "Room_Occupancy_Count")

Insights:

  1. from the above graphs we can see that there doesn’t seem to be any linear corelation between S1_Temp and Room_occupancy_count.
  2. You can observe how the distribution of room occupancy varies with different values of “S6_PIR.” Higher values of “S6_PIR” may correspond to higher room occupancy, while lower values may indicate lower occupancy.