Section 1: Dataset Description

The original source of the dataset is: http://www.capitalbikeshare.com/system-data.The data was generated by 500 bike-sharing programs and was collected by the Laboratory of Artificial Intelligence and Decision Support (LIAAD), University of Porto. The data was aggregated on hourly and daily basis. Following that, the corresponding weather and seasonal information were extracted from http://www.freemeteo.com and holiday schedule was extracted from http://dchr.dc.gov/page/holiday-schedule respectively.

For this project, I am only taking into account, the daily count and NOT the hourly count of bike rentals.

bike.sharing <- read.delim("C:/Users/Rushil/Desktop/bike.sharing.txt") ### Importing the data set
nrow(bike.sharing) ### number of rows in the dataset
## [1] 731
ncol(bike.sharing) ### number of columns in the dataset
## [1] 16
names(bike.sharing) ### names of the columns in the dataset
##  [1] "instant"    "dteday"     "season"     "yr"         "mnth"      
##  [6] "holiday"    "weekday"    "workingday" "weathersit" "temp"      
## [11] "atemp"      "hum"        "windspeed"  "casual"     "registered"
## [16] "cnt"
dim(bike.sharing) ### dimensions of the dataset. 
## [1] 731  16

There were 731 rows and 16 columns originally in the dataset. A number of new columns were created for this project which will be described shortly.

The names of the original columns and their descriptions are as follows:

1) instant: refers to the record index.

2) dteday: refers to the date.

3) season: season wherein (1:winter,2:spring, 3:summer, 4:fall)

4) yr: year(0:2011, 1:2012).

5) mnth: months, 1 to 12.

6) holiday: whether the day is a holiday (0) or not (1).

7) weekday: refers to the day of the week (0 to 6).

8) workingday: if the day is neither weekend nor a holiday then it is represented as 1, otherwise 0.

9) weathersit: refers to the weather situation, wherein 1: Clear, Few clouds, Partly cloudy. 2: Mist + Cloudy, Mist + Broken clouds, Mist + Few clouds, Mist. 3: Light Snow, Light Rain + Thunderstorm + Scattered clouds, Light Rain + Scattered clouds. 4: Heavy Rain + Ice Pallets + Thunderstorm + Mist, Snow + Fog

10) temp: refers to normalized temperature in Celsius. The values are derived via (t-t_min)/(t_max-t_min), t_min=-8, t_max=+39 (only in hourly scale).

11) atemp: refers to normalized feeling temperature in Celsius. The values are derived via (t-t_min)/(t_max-t_min), t_min=-16, t_max=+50 (only in hourly scale).

12) hum: refers to normalized humidity. The values are divided to 100 (max).

13) windspeed: refers to normalized wind speed. The values are divided to 67 (max).

14) casual: refers to number of casual users.

15) registered: refers to number of registered users.

16) cnt: refers to total count of rental bikes including both casual and registered users.

Newly added columns:

1) converted.temp: refers to the converted temperatures from normalised to raw temperatures using the given formula (t-t_min)/(t_max-t_min), t_min=-8, t_max=+39.

2) converted.atemp: refers to the converted temperatures from normalised feeling temperatures to raw feeling temperatures using the given formula (t-t_min)/(t_max-t_min), t_min=-16, t_max=+50.

3) mean.converted.temp.atemp: refers to the total temperature, calculated by determining the means of converted.temp(converted real temperature) and converted.atemp(converted feeling of the temperature).

Note:

The new columns were added in the copy (bike.sharingcopy) of the dataset which was created for the project.

Additionally, the season column was recoded from numbers to characters in the bike.sharingcopy dataset.

For the analysis of temperature, feeling of temperature, and season, the newly added or recoded columns were considered.

Section 2: Research Questions

1) What is the average number of casual and registered bikes rented on a working day?

2) What are the total number of bikes rented per month?

3) How did the temperatures change in different seasons? Show histograms of seasons where the highest and the lowest mean and median temperatures were recorded.

4) How did the total count of rental bikes change across seasons?

5) What is the difference between temperatures in temp(real temperature)and atemp(feeling of the temperature)?

6) Determine the correlation between total temperature (converted.temp + converted.atemp) and total number of rental bikes.

7) Using a scatterplot, show the relationship between temperature(real) and type of bike rentals ; casual and registered.

8) Are holidays and weather situation good predictors of total number of bikes rented?

Section 3: Data Analysis

### Loading required package for analysis
library(yarrr)
### Before starting to answer the questions I am going to check for the nature of the values in the dataset.

### Checking for null values in the dataset 
is.null(bike.sharing)
## [1] FALSE
### Checking to see if all the values in the vectors are integers
is.integer(bike.sharing) 
## [1] FALSE
### Checking for a general summary and NA values
summary(is.na(bike.sharing))  
##   instant          dteday          season            yr         
##  Mode :logical   Mode :logical   Mode :logical   Mode :logical  
##  FALSE:731       FALSE:731       FALSE:731       FALSE:731      
##  NA's :0         NA's :0         NA's :0         NA's :0        
##     mnth          holiday         weekday        workingday     
##  Mode :logical   Mode :logical   Mode :logical   Mode :logical  
##  FALSE:731       FALSE:731       FALSE:731       FALSE:731      
##  NA's :0         NA's :0         NA's :0         NA's :0        
##  weathersit         temp           atemp            hum         
##  Mode :logical   Mode :logical   Mode :logical   Mode :logical  
##  FALSE:731       FALSE:731       FALSE:731       FALSE:731      
##  NA's :0         NA's :0         NA's :0         NA's :0        
##  windspeed         casual        registered         cnt         
##  Mode :logical   Mode :logical   Mode :logical   Mode :logical  
##  FALSE:731       FALSE:731       FALSE:731       FALSE:731      
##  NA's :0         NA's :0         NA's :0         NA's :0

There are no null values in the dataset.

All the values in the vectors are integers.

There are no NA values in the dataset.

Question 1: What is the average number of casual and registered bikes rented on a working day?

### Task 9
### Calculating the average number of casual and registered bikes rented on a working day using dplyr.

require(dplyr) ### Loading dplyr for calculation of mean according to working day.    
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 3.2.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
rentals.workingday <- bike.sharing %>% group_by(workingday)%>%     summarise(mean.casual = mean(casual),
    mean.registered = mean(registered))
rentals.workingday
## Source: local data frame [2 x 3]
## 
##   workingday mean.casual mean.registered
##        (int)       (dbl)           (dbl)
## 1          0    1371.134        2959.035
## 2          1     606.570        3978.250

For 1 (Neither a weekend nor a holiday):

1)The mean casual rentals were found to be 606.57.

2)The mean registered rentals were found to be 3978.25.

For 0 (Otherwise):

1)The mean casual rentals were found to be 1371.13.

2)The mean registered rentals were found to be 2959.03.

Question 2: What are the total number of bikes rented per month?

bike.sharingcopy <- bike.sharing ### Making a copy of the dataset.
### Loading beanplot and Rcolorbrewer for making the beanplot
library(RColorBrewer)
## Warning: package 'RColorBrewer' was built under R version 3.2.3
require("beanplot")
## Loading required package: beanplot
## Warning: package 'beanplot' was built under R version 3.2.3
bean.cols <- lapply(brewer.pal(6, "Set3"),
function(x) {return(c(x, "black", "black", "black"))})
### Task 8 
### Plotting the dependent variable : total count, for each level of categorical independent variable : months (1:12) using beanplot.

beanplot(cnt ~ mnth,
data = bike.sharingcopy,
main = "Relationship between Months and Total Rentals",
xlab = "Months",
ylab = "Total Rentals",
col = bean.cols ,
lwd = 1,
what = c(1, 1, 1, 1), log = ""
)

Question 3: How did the temperatures change in different seasons? Show histograms of seasons where the highest and the lowest mean and median temperatures were recorded.

### Task 1
### First I will recode the values in the season column from numbers to characters using indexing and reassigning.
### 1 = Winter
### 2 = Spring
### 3 = Summer 
### 4 = Fall

as.character(bike.sharingcopy$season,stringsAsFactors=FALSE)   
##   [1] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
##  [18] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
##  [35] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
##  [52] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
##  [69] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "2" "2" "2" "2" "2" "2"
##  [86] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [103] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [120] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [137] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [154] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [171] "2" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [188] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [205] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [222] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [239] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [256] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "4" "4" "4" "4" "4" "4" "4"
## [273] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [290] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [307] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [324] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [341] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "1" "1" "1"
## [358] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
## [375] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
## [392] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
## [409] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
## [426] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
## [443] "1" "1" "1" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [460] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [477] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [494] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [511] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "2"
## [528] "2" "2" "2" "2" "2" "2" "2" "2" "2" "2" "3" "3" "3" "3" "3" "3" "3"
## [545] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [562] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [579] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [596] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [613] "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3" "3"
## [630] "3" "3" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [647] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [664] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [681] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [698] "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4" "4"
## [715] "4" "4" "4" "4" "4" "4" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
winter.vec <- bike.sharingcopy$season =="1"
bike.sharingcopy$season[winter.vec] <- "winter"

spring.vec <- bike.sharingcopy$season =="2"
bike.sharingcopy$season[spring.vec] <- "spring"

summer.vec <- bike.sharingcopy$season =="3"
bike.sharingcopy$season[summer.vec] <- "summer"

fall.vec<- bike.sharingcopy$season =="4"
bike.sharingcopy$season[fall.vec] <- "fall"

table(bike.sharingcopy$season)
## 
##   fall spring summer winter 
##    178    184    188    181
### Task 10

### Next, I am going t create a custom function to convert the normalised temperatures using the formula given in the dataset description, (t-t_min)/(t_max-t_min), t_min=-8, t_max=+39.
### x = (t-t_min)/(t_max-t_min), where x is the the normalised temperature, t is the temperature to be found, t-min is -8 and t-max is 39. 

### Custom function for converting normalised (real) temperatures to raw temperatures. 
formula.temp <- function(x, max, min){
  output <- x * (max - min) + min
  return(output)
}

formula.temp(x = bike.sharingcopy$temp, max = 39, min = -8)
##   [1]  8.175849  9.083466  1.229108  1.400000  2.666979  1.604356  1.236534
##   [8] -0.245000 -1.498349 -0.910849 -0.052723  0.118169 -0.245000 -0.439110
##  [15]  2.966651  2.888349  0.264151  2.183349  5.732178  4.298349  0.342500
##  [22] -5.220871 -3.463480 -3.422609  2.503466  2.222500  1.165000  1.563466
##  [29]  1.236534  2.176534  0.499151  1.032178  4.220000  0.786979  1.931288
##  [36]  2.966651  5.434151  4.768349  2.379151 -1.665199 -1.215644  0.887277
##  [43]  2.457500  6.876534 11.505000  4.506089  6.958267 12.484151 16.518349
##  [50] 10.760849  5.405199  6.256651  0.564434  2.421733  5.895644  9.124356
##  [57]  5.277500  8.143466 11.141831  4.533349  7.745000  1.321651  4.298349
##  [64] 10.055849  9.696534  4.301733  5.747500  5.904151 10.287277  6.876534
##  [71]  7.470849 10.064356  7.285199  6.917377  9.165199 11.505000 17.380000
##  [78] 14.207500  7.627500 12.230445 12.758349  8.306979  5.395000  4.415849
##  [85]  4.494151  3.893021  4.424356  6.217500  6.100000  4.611651  6.100000
##  [92]  6.805000  9.781651 18.946651 11.465849 10.369151 12.562500  7.784151
##  [99]  8.097500 12.053349 19.995644 15.617500 11.387500 13.972500 12.993349
## [106] 12.249151 13.463349 16.087500 15.774151 19.965000 13.580849  7.823349
## [113] 13.620000 19.338349 20.513349 21.688349 21.140000 21.022500 15.970000
## [120] 14.207500 13.228349 17.810849 20.983349 11.465849 13.580849 14.520849
## [127] 16.440000 16.831651 17.027500 17.027500 17.497500 17.145000 16.087500
## [134] 16.479151 18.437500 19.142500 18.398349 17.850000 16.949151 17.223349
## [141] 20.317500 20.395849 21.688349 23.020000 23.059151 25.291651 24.038349
## [148] 22.824151 23.372500 26.466651 28.425000 27.915849 25.605000 21.140000
## [155] 21.845000 22.471651 23.881651 25.252500 28.464151 29.991651 27.485000
## [162] 26.075000 24.547500 21.845000 20.395849 21.453349 21.531651 22.510849
## [169] 24.743349 24.860849 21.845000 23.999151 26.466651 26.231651 26.035849
## [176] 24.665000 23.960000 24.077500 26.975849 26.231651 24.743349 25.957500
## [183] 26.701651 25.683349 26.153349 27.093349 25.840000 27.250000 25.330849
## [190] 26.466651 27.132500 27.837500 29.325849 27.093349 23.999151 23.176651
## [197] 24.273349 25.800849 27.093349 28.503349 28.111651 30.305000 31.871651
## [204] 31.910849 31.010000 26.936651 28.268349 28.425000 28.620849 31.401651
## [211] 29.795849 29.874151 28.268349 28.816651 26.388349 25.370000 25.409151
## [218] 25.683349 26.897500 27.955000 28.425000 28.033349 25.722500 25.291651
## [225] 24.234151 23.803349 23.294151 24.939151 25.996651 25.448349 24.195000
## [232] 24.782500 25.409151 24.508349 22.119151 23.646651 24.155849 24.900000
## [239] 23.960000 25.231773 21.923349 22.040849 22.863349 22.785000 22.236651
## [246] 23.450849 25.330849 23.646651 17.380000 20.160849 21.793911 22.550000
## [253] 23.020000 22.706651 22.284356 22.589151 23.646651 19.142500 14.050849
## [260] 15.108349 15.852500 17.810849 18.398349 19.965000 21.531651 20.630849
## [267] 20.513349 21.805849 22.510849 21.923349 21.845000 20.983349 18.515849
## [274] 11.270000  8.763349 10.055849 14.755849 17.301651 15.225849 16.009151
## [281] 16.518349 17.419151 18.829151 18.633349 17.536651 19.690849 17.889151
## [288] 15.813349 16.048349 17.105849 17.027500 17.461733 14.364151 12.092500
## [295] 11.857500 11.818349 13.776651 14.168349 14.755849 14.090000  7.549151
## [302]  3.945849  7.000849  7.980000 10.839151  9.742500 11.191651 10.956651
## [309]  7.353349  8.371651 10.565000 11.191651 10.800000  9.860000  7.235849
## [316]  8.763349 12.719151 16.910000 16.910000 13.463349  8.058349  4.885849
## [323]  7.470849 13.776651 13.032500 11.583349 12.719151  9.546651  9.625000
## [330]  9.664151 13.580849 15.663466 13.541651  7.275000  6.687500  6.765849
## [337]  6.060849  7.549151 10.134151 13.737500 11.270000  4.494151  5.669151
## [344]  4.925000  2.379151  3.201651  5.277500  6.922500 11.857500  9.625000
## [351]  4.141651  3.201651  5.003349 10.134151 12.131651 11.896651  9.546651
## [358]  6.217500  4.914801  7.121733  7.275000  6.059110  3.671651  6.648349
## [365] 11.270000  9.390000  4.833021 -0.950000 -2.947500  4.494151  7.705849
## [372] 10.486651  7.862500  2.535849  6.508712  4.885849  9.977500  4.885849
## [379]  0.460000 -0.166651  0.930000  9.533021  6.256651  0.930000  2.222500
## [386]  0.146651 -0.362500  2.261651  8.097500  5.825849  8.058349 11.975000
## [393]  6.844151  5.277500  4.650849 10.330000 14.050849 10.760849  6.726651
## [400]  4.415849  4.494151  5.282623  8.645849  4.063349  4.455000  5.199151
## [407]  2.535849 -2.007500  2.457500  7.000849  8.371651  6.883349  8.136651
## [414]  8.293349  5.160000  5.160000  5.527822 10.604151 13.345849 11.152500
## [421]  5.669151  5.120849  9.233349  8.880849  8.184356 14.834151  8.606651
## [428] 11.465849  7.314151  3.436651  4.141651 10.995849 16.792500 11.309151
## [435]  5.512500  9.001733 13.933349 18.555000 18.907500 18.202500 12.484151
## [442] 16.165849 14.207500 17.615000 18.359151 16.988349 18.045849 20.278349
## [449] 15.617500 12.562500 12.954151  7.196651 14.755849 15.225849  9.390000
## [456] 11.935849 12.014151 12.393911 13.933349 17.458349 12.445000 10.956651
## [463] 12.562500 15.500000 14.990849 12.993349  8.388712 10.682500 12.797500
## [470] 15.265000 20.513349 23.215849 20.591651 13.776651 15.421651 16.753349
## [477] 18.790000 10.643349  7.118349 11.426651 14.403349 15.421651 13.502500
## [484]  9.703349 13.541651 13.815849 20.826651 18.515849 18.320000 21.492500
## [491] 21.218349 18.437500 17.262500 19.338349 19.025000 15.774151 17.066651
## [498] 18.515849 20.787500 18.946651 20.748349 21.923349 19.886651 18.515849
## [505] 20.200000 21.179151 20.121651 20.905000 21.218349 22.785000 23.960000
## [512] 24.547500 24.430000 25.487500 25.957500 22.863349 23.960000 22.745849
## [519] 19.416651 20.317500 20.082500 17.419151 18.045849 20.317500 22.510849
## [526] 25.409151 26.153349 25.879151 22.706651 22.824151 22.471651 22.040849
## [533] 21.688349 19.847500 18.711651 24.351651 28.777500 29.874151 28.542500
## [540] 26.388349 26.936651 25.644151 21.649151 24.782500 27.210849 31.205849
## [547] 27.955000 30.344151 28.738349 28.699151 29.090849 30.892500 30.931651
## [554] 32.498349 30.657500 25.409151 25.879151 25.683349 25.644151 26.388349
## [561] 25.056651 27.054151 27.876651 30.461651 29.286651 28.190000 23.294151
## [568] 20.004151 23.372500 26.858349 27.289151 26.035849 28.503349 28.738349
## [575] 27.524151 25.918349 26.349151 25.526651 25.722500 27.367500 27.994151
## [582] 29.286651 28.150849 27.367500 26.584151 27.250000 27.524151 25.644151
## [589] 24.547500 24.939151 25.879151 26.153349 25.213349 25.800849 25.996651
## [596] 23.881651 21.884151 21.884151 22.510849 23.372500 24.704151 25.017500
## [603] 23.098349 22.706651 25.056651 26.231651 24.195000 25.213349 27.915849
## [610] 27.406651 24.743349 25.252500 26.114151 26.623349 24.743349 25.056651
## [617] 22.980849 20.670000 19.416651 19.142500 20.160849 20.787500 21.766651
## [624] 20.591651 19.260000 19.299151 21.296651 17.967500 17.693349 20.160849
## [631] 22.550000 16.870849 16.165849 17.850000 21.845000 22.550000 21.100849
## [638] 17.497500 16.753349 16.479151 19.769151 22.902500 22.902500 20.905000
## [645] 18.045849 11.544151 10.016651 12.993349 16.165849 12.445000 12.562500
## [652] 10.486651 16.518349 18.398349 14.011651 13.424151 16.557500 18.476651
## [659] 14.755849 13.815849 14.912500 17.575849 19.612500 17.850000 17.654151
## [666] 16.910000 14.442500 12.680000  6.954554  8.802500  9.194151  8.685000
## [673]  8.136651  7.314151  7.000849  5.199151  5.904151  8.552178  8.998349
## [680] 10.290849 11.779151 14.795000  8.136651  5.590849  7.118349  8.215000
## [687]  7.275000  8.097500  9.899151  9.585849  8.606651  7.980000  9.311651
## [694]  5.081651  3.554151  6.726651  5.708349  5.943349  5.200890  6.021651
## [701]  6.021651  8.332500 13.267500 14.364151 12.601651  4.024151  7.079151
## [708]  9.938349 10.055849 12.484151  8.606651  5.982500  5.904151  5.238349
## [715]  7.235849  9.037500 10.486651 11.309151  7.627500  7.510000  7.353349
## [722]  4.494151  3.554151  2.871288  5.691288  3.436651  3.945849  3.906651
## [729]  3.906651  4.024151  2.144151
### Adding a new column called converted.temp to the bike.sharingcopy dataset. 

bike.sharingcopy$converted.temp <- formula.temp(x = bike.sharingcopy$temp, max = 39, min = -8)


### Custom function for converting atemp from normalised atemp to raw atemp. 
formula.atemp <- function(x, max, min){
  output <- x * (max - min) + min
  return(output)
}

formula.atemp(x = bike.sharingcopy$atemp, max = 50, min = -16)
##   [1]   7.999250   7.346774  -3.499270  -1.999948  -0.868180  -0.608206
##   [7]  -2.216626  -5.291236  -8.332450  -6.041392  -3.363376  -5.408782
##  [13]  -6.041722  -3.564742   0.375392  -0.541678  -4.333114  -0.666022
##  [19]   3.695852   0.833300  -5.583022 -10.781406  -9.476619  -8.216620
##  [25]  -0.521284  -2.562400  -1.499800  -1.261078  -1.999684   0.521252
##  [31]  -3.707500  -0.521020   0.791522  -4.260052  -0.913258   0.041828
##  [37]   3.250286   4.041428  -2.915764  -6.477322  -6.129832  -1.908406
##  [43]  -0.625036   5.391458  10.291100   0.782084   4.869200  12.291428
##  [49]  17.790878   9.832664   2.303780   2.748950  -3.721822   0.217322
##  [55]   3.086606   7.130426   2.624672   7.173194  10.407788   1.416014
##  [61]   5.124686  -2.791222   0.874814   8.999414   8.172632  -0.261574
##  [67]   3.958400   2.916128   9.454088   4.130000   5.499500   9.086006
##  [73]   5.912000   4.999748   8.217380  11.081978  18.782594  14.790650
##  [79]   5.499500  11.042510  13.082372   6.303974   1.874978   0.916592
##  [85]   0.999686   0.522374   0.999884   3.331928   3.625100   0.999950
##  [91]   2.707964   4.832042   8.998622  19.833314  10.291100   9.582128
##  [97]  12.623936   5.415614   6.540914  12.164642  21.304322  16.541564
## [103]  11.540678  14.540972  13.166258  12.082472  13.415936  17.207636
## [109]  16.291028  21.249872  13.956872   5.248964  13.707986  20.416358
## [115]  21.917000  23.209478  21.959372  22.209314  16.832558  14.625386
## [121]  13.581464  19.166978  22.417214  10.706900  13.166522  15.291722
## [127]  17.832986  18.249578  18.666236  18.499586  18.874400  18.541958
## [133]  16.623800  17.041514  19.376000  20.333792  19.542914  18.792428
## [139]  17.708972  18.916772  21.750350  21.917000  22.959536  23.917658
## [145]  24.625772  27.209408  26.042528  24.417014  24.626300  28.292072
## [151]  31.875278  31.583822  26.500172  22.750778  23.249936  24.709064
## [157]  25.042628  27.292700  32.000414  34.000214  30.417272  28.750508
## [163]  26.459450  23.709164  23.042036  22.791764  23.292836  23.625278
## [169]  26.500964  26.625836  23.292836  26.084636  29.792714  29.792978
## [175]  27.334478  26.458658  26.083514  26.042264  29.708828  27.209408
## [181]  26.042528  27.042692  28.042328  28.125950  27.917522  29.958308
## [187]  29.251778  29.333486  28.251878  27.834428  29.541650  32.167064
## [193]  32.792150  29.500664  25.916864  25.208486  26.125358  28.208978
## [199]  30.459050  33.333614  33.292100  38.540486  39.499136  37.082942
## [205]  36.458714  31.583228  30.000614  29.584022  32.833400  35.873822
## [211]  32.083442  32.166536  30.417272  30.666686  28.875842  27.876008
## [217]  27.333422  28.626164  31.209272  30.416678  31.791986  29.208878
## [223]  27.000386  27.166772  26.626628  25.209608  24.667022  26.625242
## [229]  28.000286  27.709028  25.792586  26.833736  28.584650  26.124764
## [235]  24.000422  25.625672  26.626364  27.542378  25.946696  26.765294
## [241]  24.125228  23.250464  24.333986  24.584786  23.917328  25.792058
## [247]  27.918314  25.292636  18.003200  19.919114  20.653826  22.210436
## [253]  24.125492  24.209114  23.740580  23.834564  25.375400  20.542286
## [259]  14.457350  15.581792  16.375442  18.958550  19.126322  20.335178
## [265]  20.627558  18.460250  21.251192  21.794042  22.876772  21.918650
## [271]  21.960428  21.917792  19.958714  11.248958   6.790922   9.875036
## [277]  15.208628  18.791108  15.708050  17.290664  17.873972  18.582878
## [283]  19.833050  20.042336  18.169322  20.419064  18.958550  16.915850
## [289]  17.208164  17.707850  18.499586  17.913968  14.790650  11.957336
## [295]  12.082472  11.873978  14.166422  14.582750  15.207836  14.165036
## [301]   5.041592  -0.957742   5.207714   7.500158  10.207808   9.748778
## [307]  10.790786  10.623872   5.374364   7.915628  10.457486  11.208236
## [313]  10.999214   8.665586   4.249922   7.624172  12.416300  18.624392
## [319]  17.500214  13.831208   5.332586   1.999586   5.415878  14.165828
## [325]  13.374092  11.831936  12.415442   8.583086   9.124286   9.415742
## [331]  14.082800  16.348052  13.790750   4.540586   4.166564   5.874578
## [337]   4.499864   7.040600   9.999050  14.122400  10.416236   0.957908
## [343]   4.957772   1.583192   0.708164   1.832936   3.875108   6.331892
## [349]  11.207642   7.748450   0.458486   0.208214   2.541578  10.165964
## [355]  12.249122  12.123986   8.915858   3.749972   2.477426   4.825310
## [361]   5.623778   2.478284   1.416872   5.041592  11.331986   8.790986
## [367]   0.652064  -7.665850  -8.123758   2.375192   6.457622   9.791414
## [373]   6.457028   0.333614   5.042516   2.666186   9.207908   0.457892
## [379]  -3.916258  -5.332750  -3.416242   8.042348   2.166764  -3.457492
## [385]  -1.416772  -4.458250  -5.291500   0.041828   7.041128   3.458186
## [391]   7.499300  11.415278   5.541014   1.999586   1.333250   9.166922
## [397]  14.791508  10.332086   4.416836   1.999850   1.458386   3.564116
## [403]   7.832864   1.583786   1.291208   3.374828  -2.082778  -9.290572
## [409]  -0.957742   6.040436   7.207514   5.790692   7.207514   7.458050
## [415]   1.542008   2.043806   3.477458   9.916022  13.333436  11.124086
## [421]   0.874550   1.708328   7.624964   7.332650   6.999020  15.374486
## [427]   7.749572  11.290472   3.999386  -0.082714   0.832772   9.416600
## [433]  18.623864  10.207478   2.332622   7.738220  14.333072  19.833314
## [439]  20.208722  19.166450  12.791114  17.333036  14.624000  19.166186
## [445]  19.543178  17.875028  19.083422  21.624422  16.124378  12.874208
## [451]  12.957500   4.833164  15.082700  15.832064   8.790986  11.832728
## [457]  11.540942  12.215858  14.457878  19.207700  12.456758   9.790622
## [463]  12.124514  16.500050  15.458108  12.791378   6.260084   9.581864
## [469]  12.499328  16.207736  21.875750  24.585050  23.500142  14.164508
## [475]  16.541036  18.041150  19.832786   9.707264   3.874250  10.748678
## [481]  15.040922  15.916478  13.874042   8.915264  13.707986  14.207936
## [487]  22.083386  19.501136  19.457972  23.000522  22.584128  20.084642
## [493]  18.791372  20.793086  20.499650  16.457678  18.374978  19.957922
## [499]  22.625708  20.293400  22.042664  23.334350  21.792458  20.373986
## [505]  21.415928  22.541822  21.334022  22.334450  22.584392  24.042200
## [511]  25.416914  26.417936  26.334050  28.833800  28.417472  24.334514
## [517]  25.667714  24.125492  21.375008  21.958778  22.166678  18.708872
## [523]  19.791272  21.583172  23.458892  26.792222  27.792122  27.541586
## [529]  23.459750  24.333722  25.209278  23.583764  23.250728  21.750350
## [535]  19.959572  27.209672  31.584350  33.667772  31.791986  27.084272
## [541]  28.500764  27.166772  23.250464  26.292272  28.583792  35.916458
## [547]  29.375528  33.541514  30.334508  30.374900  32.334242  34.250222
## [553]  33.667178  37.124258  36.166136  27.167564  27.876536  26.917886
## [559]  27.209078  28.083578  27.958772  30.542936  31.792250  33.875078
## [565]  33.208478  31.166372  24.459650  20.294192  25.126250  29.541122
## [571]  30.625700  27.167564  32.791358  32.458322  30.041864  28.083578
## [577]  29.209142  27.751136  28.042328  30.667808  31.709222  33.583622
## [583]  32.251214  30.876236  30.042986  30.709322  30.167528  28.084172
## [589]  26.125622  26.542214  27.708764  28.667414  27.166442  27.209408
## [595]  -0.001600  24.792686  23.834564  23.333822  23.667650  25.042364
## [601]  26.042528  26.708600  24.833936  23.335736  27.209408  27.959300
## [607]  25.958378  27.083414  29.500400  30.375164  26.834000  27.667514
## [613]  29.334608  30.792878  27.251714  27.375464  24.333986  22.209050
## [619]  21.333164  20.583272  21.624950  22.250828  23.209478  22.667222
## [625]  21.166250  20.501300  21.294422  19.666664  19.124672  21.750086
## [631]  24.292208  18.249578  17.165858  19.915814  23.376458  24.126350
## [637]  22.666958  18.999536  18.165758  17.792000  19.793978  23.542778
## [643]  24.126350  22.292342  19.542386  11.707658   9.582128  12.915392
## [649]  17.207372  12.457022  12.582686   9.832136  17.541464  19.583900
## [655]  14.415836  13.707128  17.833250  19.501136  15.207572  14.124314
## [661]  15.874172  19.000064  20.875586  18.959408  18.501500  17.998778
## [667]  14.872886  13.000400   4.453994   7.832600   8.416172   7.498772
## [673]   5.373836   5.749508   4.332950   2.583422   2.124986   6.564806
## [679]   7.457258   9.999842  11.833058  15.375278   5.332850   2.583158
## [685]   5.416472   6.915464   5.541278   6.291236   8.790986   9.124022
## [691]   8.082872   7.124486   8.999414   0.416972   1.000478   6.374264
## [697]   2.582828   3.124292   3.695852   5.375222   4.915664   7.707728
## [703]  14.082536  14.957564  12.248792   1.041464   5.249228   9.707528
## [709]   9.749636  12.747950   6.331958   3.624308   3.416408   3.416672
## [715]   6.333278   8.415908  10.499000  11.040728   6.582692   6.124322
## [721]   3.916622  -0.416542   1.125086   1.087400   3.434690  -1.458022
## [727]  -1.041628   0.833036  -0.001600  -0.707800  -1.249858
### Adding a new column called converted.atemp to the bike.sharingcopy dataset. 

bike.sharingcopy$converted.atemp <- formula.atemp(x = bike.sharingcopy$atemp, max = 50, min = -16)
### Task 2
### I am going to calculate mean, median and sd of temperature in every season.

### Mean, median and sd of temperature in Spring.
springseason <- subset(bike.sharingcopy, season == "spring")$converted.temp
mean.spring <- mean(springseason) 
mean.spring
## [1] 17.58704
median.spring <- median(springseason) 
median.spring
## [1] 18.41792
sd.spring <- sd(springseason)
sd.spring
## [1] 5.764548

1)The mean of temperature in spring was found to be 17.59.

2)The median of temperature in spring was found to be 18.42.

3)The standard deviation of temperature in spring was found to be 5.76.

### Mean, median and sd of temperature in summer.
summerseason <- subset(bike.sharingcopy, season == "summer")$converted.temp
mean.summer <- mean(summerseason) 
mean.summer
## [1] 25.19654
median.summer <- median(summerseason)
median.summer
## [1] 25.5854
sd.summer <- sd(summerseason)
sd.summer
## [1] 3.329834

1)The mean of temperature in summer was found to be 25.2.

2)The median of temperature in summer was found to be 25.59.

3)The standard deviation of temperature in summer was found to be 3.32.

### Mean, median and sd of temperature in fall.
fallseason <- subset(bike.sharingcopy, season == "fall")$converted.temp
mean.fall <- mean(fallseason) 
mean.fall
## [1] 11.87658
median.fall <- median(fallseason) 
median.fall
## [1] 11.23083
sd.fall <- sd(fallseason)
sd.fall
## [1] 5.068181

1)The mean of temperature in fall was found to be 11.88.

2)The median of temperature in spring was found to be 11.23.

3)The standard deviation of temperature in spring was found to be 5.06.

### Mean, median and sd of temperature in winter.
winterseason <- subset(bike.sharingcopy, season == "winter")$converted.temp
mean.winter <- mean(winterseason) 
mean.winter
## [1] 5.994135
median.winter <- median(winterseason) 
median.winter
## [1] 5.434151
sd.winter <- sd(winterseason)
sd.winter
## [1] 4.828546

1)The mean of temperature in winter was found to be 5.99.

2)The median of temperature in winter was found to be 5.43.

3)The standard deviation of temperature in winter was found to be 4.83.

### Task 7
### The highest mean and median temperatures were recorded in the summer season.
### Calculating the limits for the histogram using min and max function and then making the histogram  for summer season accordingly.

max(summerseason)
## [1] 32.49835
min(summerseason)
## [1] 14.05085
### The maximum temperature in summer was found to be 32.49.
### The minimum temperature in summer was found to be 14.05.

hist(x = summerseason, 
     main = "Temperature in Summer", 
     xlab = "Temperature in Degree Celsius", 
     ylab = "Days",
     xlim = c(12, 35),
     ylim = c(0, 45),
     breaks = 15,
     border = "black",
     col = "darkseagreen3")

abline(v = mean.summer, lwd = 2, lty = 1, col = "red")  
text(x = 20, y = 25, 
     labels = paste("Mean = ", round(mean(summerseason),2), sep = ""), col="red" )

abline(v = median.summer, lwd = 2, lty = 3, col = "blue") 
text(x = 27, y = 30,  labels = paste("Median = ", round(median(summerseason),2), sep = ""), col="blue" )

### The lowest mean and median temperatures were recorded in the winter season.
### calculating the limits for the histogram  and then making the histogram  for winter season accordingly

max(winterseason)
## [1] 18.9075
min(winterseason)
## [1] -5.220871
### The maximum temperature in winter was found to be 18.90.
### The minimum temperature in winter was found to be -5.22.

hist(x = winterseason, 
     main = "Temperature in Winter", 
     xlab = "Temperature in Degree Celsius", 
     ylab = "Days",
     xlim = c(-5, 20),
     ylim = c(0, 35),
     border = "black",
     col = "yellowgreen")

abline(v = mean.winter, lwd = 2, lty = 1, col = "red")  
text(x = 10, y = 15, 
     labels = paste("Mean = ", round(mean(winterseason),2), sep = ""), col="red" )

abline(v = median.winter, lwd = 2, lty = 3, col = "blue") 
text(x = 3, y = 5, 
     labels = paste("Median = ", round(median(winterseason),2), sep = ""), col="blue" )

Question 4: How did the total count of rental bikes change across seasons?

### Task 11
### Calculating the change in total count of bike rentals in different seasons by using a loop code for calculating mean, median and sd of total count of rental bikes for the four seasons. 
 
design.matrix <- expand.grid(
  "season" = c("winter", "spring", "summer", "fall"), 
  "median.cnt" = NA, 
  "mean.cnt" = NA, 
  "sd.cnt" = NA, 
  stringsAsFactors = F
)

design.matrix 
##   season median.cnt mean.cnt sd.cnt
## 1 winter         NA       NA     NA
## 2 spring         NA       NA     NA
## 3 summer         NA       NA     NA
## 4   fall         NA       NA     NA
for(row.i in 1:nrow(design.matrix)) {
  
season.i <- design.matrix$season[row.i]
data.temp <- subset(bike.sharingcopy, season == season.i) ### adding the information in a temporary folder. 
  
### Calculating descriptive statistics mean, median and sd. 
median.i <- median(data.temp$cnt)
mean.i <- mean(data.temp$cnt)
sd.i <- sd(data.temp$cnt)

### Assigning statistics to row.i of design.matrix
design.matrix$median.cnt[row.i] <- median.i
design.matrix$mean.cnt[row.i] <- mean.i
design.matrix$sd.cnt[row.i] <- sd.i
}
design.matrix
##   season median.cnt mean.cnt   sd.cnt
## 1 winter     2209.0 2604.133 1399.942
## 2 spring     4941.5 4992.332 1695.977
## 3 summer     5353.5 5644.303 1459.800
## 4   fall     4634.5 4728.163 1699.615

Winter

1)The mean of total rentals in winter was found to be 2604.13.

2)The median of total rentals in winter was found to be 2209.

3)The sd of total rentals in winter was found to be 1399.94.

Spring

1)The mean of total rentals in spring was found to be 4992.33.

2)The median of total rentals in spring was found to be 4941.5.

3)The sd of total rentals in spring was found to be 1695.98.

Summer

1)The mean of total rentals in summer was found to be 5644.30.

2)The median number of total rentals in summer was found to be 5353.5.

3)The sd of total rentals in summer was found to be 1459.8.

Fall

1)The mean of total rentals in fall was found to be 4728.16.

2)The median of total rentals in fall was found to be 4634.5.

3)The sd of total rentals in fall was found to be 1699.62.

Question 5: What is the difference between temperatures in temp(real temperature)and atemp(feeling of the temperature)?

### First, I will run the apa custom function code for all the analysis requiring apa format results.
apa <- function(test.object, tails = 2, sig.digits = 2, p.lb = .01) {

  statistic.id <- substr(names(test.object$statistic), start = 1, stop = 1)
  p.value <- test.object$p.value

  if(tails == 1) {p.value <- p.value / 2}

  if (p.value < p.lb) {p.display <- paste("p < ", p.lb, " (", tails, "-tailed)", sep = "")}
  if (p.value > p.lb) {p.display <- paste("p = ", round(p.value, sig.digits), " (", tails, "-tailed)", sep = "")}


  add.par <- ""

  if(grepl("product-moment", test.object$method)) {

    estimate.display <- paste("r = ", round(test.object$estimate, sig.digits), ", ", sep = "")

  }

  if(grepl("Chi", test.object$method)) {

    estimate.display <- ""

    add.par <- paste(", N = ", sum(test.object$observed), sep = "")

  }

  if(grepl("One Sample t-test", test.object$method)) {

    estimate.display <- paste("mean = ", round(test.object$estimate, sig.digits), ", ", sep = "")

  }

  if(grepl("Two Sample t-test", test.object$method)) {

    estimate.display <- paste("mean difference = ", round(test.object$estimate[2] - test.object$estimate[1], sig.digits), ", ", sep = "")

  }




  return(paste(
    estimate.display,
    statistic.id,
    "(",
               round(test.object$parameter, sig.digits),
               add.par,
               ") = ",
               round(test.object$statistic, sig.digits),
               ", ",
               p.display,
               sep = ""
  )
  )

}
### Task 3
### Calculating t-test for the difference between temp(real temperature) and atemp (feeling of the temperature).
testresult.temp <- t.test(x = bike.sharingcopy$converted.temp, y = bike.sharingcopy$converted.atemp, alternative = "two.sided")
testresult.temp
## 
##  Welch Two Sample t-test
## 
## data:  bike.sharingcopy$converted.temp and bike.sharingcopy$converted.atemp
## t = -0.047659, df = 1392.8, p-value = 0.962
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.0235835  0.9750271
## sample estimates:
## mean of x mean of y 
##  15.28309  15.30736
apa(testresult.temp)
## [1] "mean difference = 0.02, t(1392.82) = -0.05, p = 0.96 (2-tailed)"
### There is not a significant difference between real temperature and feeling of the temperature, mean difference = 0.02, t(1392.82) = -0.05, p = 0.96 (2-tailed).
### Alternative Hypothesis confirmed: true difference in means is not equal to 0. 

Question 6: Determine the correlation between total temperature (converted.temp + converted.atemp) and total number of rental bikes.

### Task 4
### Determining the correlation between total temperature and total count of bike using cor test.  

### For determining the total temperature, first I will find the mean of converted.temp and converted.atemp and add it as a new column in bike.sharingcopy dataset.
bike.sharingcopy$mean.converted.temp.atemp <- (bike.sharingcopy$converted.temp + bike.sharingcopy$converted.atemp)/2

### Correlation between total temperature and total count
cor.mean.converted.temp.atemp <- cor.test(x = bike.sharingcopy$mean.converted.temp.atemp,
y = bike.sharingcopy$cnt)
cor.mean.converted.temp.atemp
## 
##  Pearson's product-moment correlation
## 
## data:  bike.sharingcopy$mean.converted.temp.atemp and bike.sharingcopy$cnt
## t = 21.948, df = 729, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5850170 0.6725248
## sample estimates:
##       cor 
## 0.6307721
apa(cor.mean.converted.temp.atemp)
## [1] "r = 0.63, t(729) = 21.95, p < 0.01 (2-tailed)"
### There is a significant positive correlation between total temperature and total bike rentals,  r = 0.63, t(729) = 21.95, p < 0.01 (2-tailed).

Question 7: Using a scatterplot, show the relationship between temperature(real) and type of bike rentals ; casual and registered.

### Task 6
### creating objects for plotting the relevant data.
Temperature <- bike.sharingcopy$converted.temp
Casual.rentals <- bike.sharingcopy$casual
Registered.rentals <- bike.sharingcopy$registered

### creating a scatterplot for showing correlation between temperature and type of bike rentals; casual and registered with added regression lines. 
### For determining the limits of x and y axis I will use min and max function. 
min(bike.sharingcopy$casual)
## [1] 2
max(bike.sharingcopy$casual)
## [1] 3410
min(bike.sharingcopy$registered)
## [1] 20
max(bike.sharingcopy$registered)
## [1] 6946
min(bike.sharingcopy$converted.temp)
## [1] -5.220871
max(bike.sharingcopy$converted.temp)
## [1] 32.49835
### The limits of the variables are 40 for temperature and 7000 for bike rentals
### Plotting the correlation using scatterplot 
plot(x = 1, y = 1, xlab = "Temperature in degree celsius", ylab = "Bike rentals", type = "n", main = "Correlation between temperature and type of bike rentals",
xlim = c(0, 40), ylim = c(0, 7000))
### Adding points, regression lines and legends in the following code
points(bike.sharingcopy$converted.temp, bike.sharingcopy$casual, pch = 10, col = "purple")
points(bike.sharingcopy$converted.temp, bike.sharingcopy$registered, pch = 10, col = "orange")
legend("topright",legend = c("casual", "registered"), col = c("purple","orange"), pch = c(10, 10), bg = "grey")
abline(lm(bike.sharingcopy$registered ~ bike.sharingcopy$converted.temp), lty = 6, col = "blue")

abline(lm(bike.sharingcopy$casual ~ bike.sharingcopy$converted.temp), lty = 6, col = "red")
abline(lm(bike.sharingcopy$registered ~ bike.sharingcopy$converted.temp), lty = 6, col = "hotpink")

registered <- paste("cor = ", round(cor(bike.sharingcopy$registered, bike.sharingcopy$converted.temp), 2), sep = "")
casual <- paste("cor = ", round(cor(bike.sharingcopy$casual, bike.sharingcopy$converted.temp), 2), sep = "")

legend("left",legend = c(registered, casual) , col = c('red', 'hotpink'),pch = c(10, 10), bg = "grey")

Question 8: Are holidays and weather situation good predictors of total number of bikes rented?

### Task 5

### Regression analysis using lm model. 
total.rentals.lm <- lm(cnt ~ weathersit + holiday, data = bike.sharingcopy)
summary(total.rentals.lm) 
## 
## Call:
## lm(formula = cnt ~ weathersit + holiday, data = bike.sharingcopy)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4521.4 -1267.9   -61.4  1494.1  4476.6 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   6019.4      188.6  31.910   <2e-16 ***
## weathersit   -1067.0      125.5  -8.505   <2e-16 ***
## holiday       -912.5      408.9  -2.231    0.026 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1846 on 728 degrees of freedom
## Multiple R-squared:  0.09463,    Adjusted R-squared:  0.09215 
## F-statistic: 38.05 on 2 and 728 DF,  p-value: < 2.2e-16
### The coefficients (Intercept, weathersit and holiday) were found to be 6019.4, -1067.0 and -912.5.

### The df.residuals are 728.

### Use of Anova to test the effect of weather situation and holiday
anova.weathersit <- anova (total.rentals.lm)
anova.weathersit
## Analysis of Variance Table
## 
## Response: cnt
##             Df     Sum Sq   Mean Sq F value  Pr(>F)    
## weathersit   1  242288753 242288753 71.1154 < 2e-16 ***
## holiday      1   16964654  16964654  4.9794 0.02595 *  
## Residuals  728 2480281985   3406981                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
### The f-values of weather situation and holiday were found to be : 
anova.weathersit$`F value`
## [1] 71.115387  4.979381        NA
#### The p-values of weather situation and holiday were found to be : 
anova.weathersit$`Pr(>F)`
## [1] 1.803533e-16 2.595486e-02           NA
### The analysis of variance showed a significant effect for weather situation (F-value = 71.11, Df = 1, p-value < 0.01) but not for holiday (F-value = 4.979, Df = 1, p-value = 0.025). 

Section 4: Conclusions

In general, it was seen that the number of registered users was overall higher compared to that of casual users. Specifically when classified by working days it was found that more number of registered bikes were rented on occasions when it was neither a weekend nor a holiday as compared to casual bike rentals which were more during situations (1) when it could have been a weekend or a holiday. This possibly helps us to have an understanding of purpose and type of bike rentals. Registered users might use bikes on a daily basis, example for work or other day to day activities where as casual bike rentals are associated with holiday and leisure.

The highest number of bike rentals were between the months of June and August, whereas the lowest number of bike rentals were between the months November and February. This gives us an indication about the role of corresponding seasons associated with these months. Furthermore, I also checked for total count of bike rentals across seasons which confirms that the highest rentals were during summer followed by spring, fall and lastly in winter.

Bike sharing programs in the future must take into consideration, the results observed. Maybe some additional incentives or amenities (like better accessories with the bikes) can be provided for increasing the rentals during off- seasons like winter and maybe fall.