<jupyter_start><jupyter_text>Ad Click Analysis  Overview**i. Understanding the context**  A Kenyan entrepreneur has created an online cryptography course and would want to advertise it on her blog. She currently targets audiences originating from various countries. In the past, she ran ads to advertise a related course on the same blog and collected data in the process. She would now like to employ our services as Data Science Consultants to help her identify which individuals are most likely to click on her ads. **ii. Specifying the objectives**  The specific objective of this project is:  > To identify the individuals who are most likely to click on the client's ads**iii. Defining the metric for success**  The project will be considered successful when we accurately identify the individuals who are most likely to click on the client's ads.   **iv. Data relevance**  The appropriate dataset for this project is one that contains data  on the characteristics of the individuals who read the client's blogs.We have retrieved a data set from http://bit.ly/IPAdvertisingData' and its appropriateness will be measured against the metrics of success.**v. Project design**  In order to work on the above problem, we need to do the following:a. Acquire the dataset with appropriate data for our project  b. Perform data cleaning by dropping irrelevant data, finding and dealing with duplicates, missing data, and anomalies   c. Perform univariate and bivariate analysis to gain insights on the given data d. Give conclusions and recommendations   Loading relevant packages<jupyter_code># load data.table package
library("data.table")
# load tidyverse package
library("tidyverse")
# install cutr package from github
devtools::install_github("moodymudskipper/cutr")
# load cutr package
library(cutr)
# install modeest package form github
devtools::install_github("paulponcet/modeest")
# load modeest package
library(modeest)
# install moments package
install.packages('moments')
# load moments package
library(moments)
# install janitor package
install.packages('janitor')
# load janitor package 
library(janitor)<jupyter_output><empty_output><jupyter_text>Loading the dataset<jupyter_code># load the dataset using fread funcion and instantiate it\
data <- fread('http://bit.ly/IPAdvertisingData')<jupyter_output><empty_output><jupyter_text>Reading the data<jupyter_code># preview the first few records in the dataset
head(data)
# find number of rows and columns in the dataframe using dim() function
dim(data)<jupyter_output><empty_output><jupyter_text>There are 1000 rows and 10 columns in the dataframe<jupyter_code># check the data type of each variable using sapply() function
sapply(data, class)<jupyter_output><empty_output><jupyter_text>"Clicked on Ad" and "Male" are categorical variables even though they have numeric values. Their data types will be changed in the data cleaning section.   Data cleaning<jupyter_code># Standardize column names by lowering the case and replacing the spaces with underscores

# replace the spaces with underscores using gsub() function
names(data) <- gsub(" ","_", names(data))

# lower the case of the column names using tolower() function
names(data) <- tolower(names(data))

# display the column names to confirm the changes
colnames(data)
# find number of duplicated rows using anyDuplicated() function
anyDuplicated(data)<jupyter_output><empty_output><jupyter_text>There are no duplicated rows in the dataframe<jupyter_code># find the number of missing values in each column using is.na() and colSums() functions
colSums(is.na(data))<jupyter_output><empty_output><jupyter_text>There are no missing values in any of the columns<jupyter_code># plot a boxplot to check for outliers in the 'daily_time_spent_on_site' column
boxplot(data$daily_time_spent_on_site, main="Boxplot for Daily Time Spent on Site", xlab = "Time spent on site daily", ylab = "Value", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)

# display the number of outlier values in the column
outlier_time_on_site <- boxplot.stats(data$daily_time_spent_on_site)$out
mtext(paste("Outliers: ", paste(length(outlier_time_on_site), collapse=", ")), cex=1)<jupyter_output><empty_output><jupyter_text>There are no outliers in the 'daily_time_spent_on_site' column<jupyter_code># plot a boxplot to check for outliers in the 'age' column
boxplot(data$age, main="Boxplot for Age", xlab = "Age", ylab = "Value", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)

# display number of outlier values in the column
outlier_age <- boxplot.stats(data$age)$out
mtext(paste("Outliers: ", paste(length(outlier_age), collapse=", ")), cex=1)<jupyter_output><empty_output><jupyter_text>There are no outliers in the 'age' column<jupyter_code># plot a boxplot to check for outliers in the 'area_income' column
boxplot(data$area_income, main="Boxplot for Area Income", xlab = "Area income", ylab = "Value", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)

# display the number of outlier values in the column
outlier_income <- boxplot.stats(data$area_income)$out
mtext(paste("Outliers: ", paste(length(outlier_income), collapse=", ")), cex=1)<jupyter_output><empty_output><jupyter_text>Since the outliers in the column represent accurate values, we have no justifiable reason to drop them; for this reason, the outliers will be retained<jupyter_code># plot a boxplot to check for outliers in the 'daily_internet_usage' column
boxplot(data$daily_internet_usage, main="Boxplot for Daily Time Internet Usage", xlab = "Daily internet usage", ylab = "Value", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)

# display the outliers 
outlier_internet_usage <- boxplot.stats(data$daily_internet_usage)$out
mtext(paste("Outliers: ", paste(length(outlier_internet_usage), collapse=", ")), cex=1)<jupyter_output><empty_output><jupyter_text>There are no outliers in the 'daily_internet_usage' column<jupyter_code># check for anomalies in the 'city' column by scrutinizing its unique values 
print(unique(data$city))<jupyter_output>[1] "Wrightburgh"             "West Jodi"              
  [3] "Davidton"                "West Terrifurt"         
  [5] "South Manuel"            "Jamieberg"              
  [7] "Brandonstad"             "Port Jefferybury"       
  [9] "West Colin"              "Ramirezton"             
 [11] "West Brandonton"         "East Theresashire"      
 [13] "West Katiefurt"          "North Tara"             
 [15] "West William"            "New Travistown"         
 [17] "West Dylanberg"          "Pruittmouth"            
 [19] "Jessicastad"             "Millertown"             
 [21] "Port Jacqueline"         "Lake Nicole"            
 [23] "South John"              "Pamelamouth"            
 [25] "Harperborough"           "Port Danielleberg"      
 [27] "West Jeremyside"         "South Cathyfurt"        
 [29] "Palmerside"              "West Guybury"           
 [31] "Phelpschester"           "Lake Melindamouth"      
 [33] "North Richardburgh"      "Port Cassie"            
 [35] "New Tho[...]<jupyter_text>There are 969 unique values and no anomalies in the 'city' column<jupyter_code># check for anomalies in the 'ad_topic_line' column by scrutinizing its unique values 
print(unique(data$ad_topic_line))<jupyter_output>[1] "Cloned 5thgeneration orchestration"                     
   [2] "Monitored national standardization"                     
   [3] "Organic bottom-line service-desk"                       
   [4] "Triple-buffered reciprocal time-frame"                  
   [5] "Robust logistical utilization"                          
   [6] "Sharable client-driven software"                        
   [7] "Enhanced dedicated support"                             
   [8] "Reactive local challenge"                               
   [9] "Configurable coherent function"                         
  [10] "Mandatory homogeneous architecture"                     
  [11] "Centralized neutral neural-net"                         
  [12] "Team-oriented grid-enabled Local Area Network"          
  [13] "Centralized content-based focus group"                  
  [14] "Synergistic fresh-thinking array"                       
  [15] "Grass-roots coherent extranet"                          
  [16] "Persistent demand[...]<jupyter_text>There are 1000 unique values and no anomalies in the 'ad_topic_line' column<jupyter_code># check for anomalies in the 'male' column by scrutinizing its unique values 
print(unique(data$male))<jupyter_output>[1] 0 1<jupyter_text>There are 2 unique values and no anomalies in the 'male' column<jupyter_code># rename the 'male' column to 'gender'
names(data)[names(data) == "male"] <- "gender"

# replace the ones and zeros in 'gender' column with 'male' and 'female' using the ifelse() function
data$gender <- ifelse(data$gender == 1,"Male", 'Female')

# check for anomalies in the 'country' column by scrutinizing its unique values 
print(unique(data$country))<jupyter_output>[1] "Tunisia"                                            
  [2] "Nauru"                                              
  [3] "San Marino"                                         
  [4] "Italy"                                              
  [5] "Iceland"                                            
  [6] "Norway"                                             
  [7] "Myanmar"                                            
  [8] "Australia"                                          
  [9] "Grenada"                                            
 [10] "Ghana"                                              
 [11] "Qatar"                                              
 [12] "Burundi"                                            
 [13] "Egypt"                                              
 [14] "Bosnia and Herzegovina"                             
 [15] "Barbados"                                           
 [16] "Spain"                                              
 [17] "Palestinian Territory"           [...]<jupyter_text>There are 237 unique values and no anomalies in the 'country' column<jupyter_code># check for anomalies in the 'clicked_on_ad' column by scrutinizing its unique values 
print(unique(data$clicked_on_ad))<jupyter_output>[1] 0 1<jupyter_text>There are 2 unique values and no anomalies in the 'clicked_on_ad' column<jupyter_code># replace the ones and zeros in 'clicked_on_ad' column with 'yes' and 'no' using the ifelse() function
data$clicked_on_ad <- ifelse(data$clicked == 1,"Yes", 'No')<jupyter_output><empty_output><jupyter_text>Feature engineering<jupyter_code># extract 'month', 'day' and 'hour' data from 'timestamp' column
data$month <- format(as.POSIXct(data$timestamp, format="%Y-%m-%d %H:%M:%S"), "%m")
data$part_of_month <- format(as.POSIXct(data$timestamp, format="%Y-%m-%d %H:%M:%S"), "%d")
data$part_of_day <- format(as.POSIXct(data$timestamp, format="%Y-%m-%d %H:%M:%S"), "%H")
# categorize the values in the 'part_of_month' column using ifelse() function 
data$part_of_month <- ifelse(data$part_of_month >='01' & data$part_of_month <= '10' ,"Early",
              ifelse(data$part_of_month >='11' & data$part_of_month <= '20',"Mid", "Late"))
# categorize the values in the 'part_of_day' column
data$part_of_day <- ifelse(data$part_of_day >='00' & data$part_of_day <= '02' ,"Late night",
              ifelse(data$part_of_day >='03' & data$part_of_day <= '05',"Towards morning",
              ifelse(data$part_of_day >='06' & data$part_of_day <= '08',"Early morning",
              ifelse(data$part_of_day >='09' & data$part_of_day <= '11',"Late morning",
              ifelse(data$part_of_day >='12' & data$part_of_day <= '14',"Early afternoon",
              ifelse(data$part_of_day >='15' & data$part_of_day <= '17',"Late afternoon",
              ifelse(data$part_of_day >='18' & data$part_of_day <= '20',"Evening", "Night")))))))
              
# drop irrelevant columns
setDT(data)[, c( "timestamp", "city", "ad_topic_line") := NULL]
# preview the first few records of the dataset
head(data)<jupyter_output><empty_output><jupyter_text>Univariate analysisUnivariate analysis will help us gain insights on the general characteristics of the individual variables in the dataset.  Numerical variables  Measures of central tendency  Daily time spent on site<jupyter_code># compute the measures of central tendency of values in 'daily_time_spent_on_site' column
cat('The following are the measures of central tendency of daily time spent on site', '\n')
cat("Mean:", mean(data$daily_time_spent_on_site), '\n')
cat("Median:", median(data$daily_time_spent_on_site), '\n')
cat("Mode:", mfv(data$daily_time_spent_on_site), '\n')
cat("Number of modal values:", length(mfv(data$daily_time_spent_on_site)))<jupyter_output>The following are the measures of central tendency of daily time spent on site 
Mean: 65.0002 
Median: 68.215 
Mode: 62.26 75.55 77.05 78.76 84.53 
Number of modal values: 5<jupyter_text>Age<jupyter_code># compute the measures of central tendency of values in 'age' column
cat('The following are the measures of central tendency of age', '\n')
cat("Mean:", mean(data$age), '\n')
cat("Median:", median(data$age), '\n')
cat("Mode:", mfv(data$age), '\n')
cat("Number of modal values:", length(mfv(data$age)))<jupyter_output>The following are the measures of central tendency of age 
Mean: 36.009 
Median: 35 
Mode: 31 
Number of modal values: 1<jupyter_text>Area income<jupyter_code># compute the measures of central tendency of values in 'area_income' column
cat('The following are the measures of central tendency of area income', '\n')
cat("Mean:", mean(data$area_income), '\n')
cat("Median:", median(data$area_income), '\n')
cat("Mode:", mfv(data$area_income), '\n')
cat("Number of modal values:", length(mfv(data$area_income)))<jupyter_output>The following are the measures of central tendency of area income 
Mean: 55000 
Median: 57012.3 
Mode: 13996.5 14548.06 14775.5 15598.29 15879.1 17709.98 18368.57 18819.34 19345.36 19991.72 20592.99 20856.54 21644.91 21773.22 22205.74 22456.04 22473.08 23410.75 23821.72 23936.86 23942.61 23975.35 24030.06 24078.93 24316.61 24593.33 24852.9 25371.52 25408.21 25583.29 25598.75 25603.93 25682.65 25686.34 25739.09 25767.16 26023.99 26130.93 27073.27 27086.4 27241.11 27262.51 27508.41 27964.6 28019.09 28028.74 28186.65 28210.03 28265.81 28271.84 28275.48 28357.27 28387.42 28495.21 28679.93 29359.2 29398.61 29727.79 29875.8 30227.98 30487.48 30726.26 30976 31072.44 31087.54 31092.93 31215.88 31265.75 31281.01 31343.39 31523.09 31947.65 31998.72 32006.82 32252.38 32536.98 32549.95 32593.59 32635.7 32689.04 32708.94 32847.53 33147.19 33239.2 33258.09 33293.78 33502.57 33553.9 33601.84 33813.08 33951.63 33987.27 34127.21 34191.13 34191.23 34309.24 34418.09 34886.01 34903.67 34942.26 35253.98 35[...]<jupyter_text>Daily internet usage<jupyter_code># compute the measures of central tendency of values in 'daily_internet_usage' column
cat('The following are the measures of central tendency of daily internet usage', '\n')
cat("Mean: ", mean(data$daily_internet_usage), '\n')
cat("Median: ", median(data$daily_internet_usage), '\n')
cat("Mode: ", mfv(data$daily_internet_usage), '\n')
cat("Number of modal values: ", length(mfv(data$daily_internet_usage)))<jupyter_output>The following are the measures of central tendency of daily internet usage 
Mean:  180.0001 
Median:  183.13 
Mode:  113.53 115.91 117.3 119.3 120.06 125.45 132.38 135.24 136.18 138.35 158.22 161.16 162.44 164.25 167.22 169.4 178.75 182.65 190.95 194.23 201.15 211.87 214.42 215.18 219.72 222.11 223.16 228.81 230.36 234.75 235.28 236.96 247.05 256.4 
Number of modal values:  34<jupyter_text>Measures of dispersion  Daily time spent on site<jupyter_code># compute the variance and standard deviation of the values in 'daily_time_spent_on_site' column
cat('The variance of daily time spent on site is:',var(data$daily_time_spent_on_site), '\n')
cat('The standard deviation of daily time spent on site is:',sd(data$daily_time_spent_on_site))<jupyter_output>The variance of daily time spent on site is: 251.3371 
The standard deviation of daily time spent on site is: 15.85361<jupyter_text>The standard deviation shows that the values are not so spread out from the mean and the variance shows that the degree to which each value differs from the mean is a bit high.<jupyter_code># compute the range, minimum and maximum values in 'daily_time_spent_on_site' column
cat("The minimum time spent on site is:", min(data$daily_time_spent_on_site),'minutes', '\n')
cat("The maximum time spent on site is:", max(data$daily_time_spent_on_site),'minutes', '\n')
cat('The range between the minimum and maximum time spent on site is:', (max(data$daily_time_spent_on_site)-min(data$daily_time_spent_on_site)),'minutes')
# compute the skewness and kurtosis of values in the 'daily_time_on_site' column
cat('The following are skewness and kurtosis of daily time spent on site', '\n')
cat("Skewness: ", skewness(data$daily_time_spent_on_site), '\n')
cat("Kurtosis: ", kurtosis(data$daily_time_spent_on_site), '\n')<jupyter_output>The following are skewness and kurtosis of daily time spent on site 
Skewness:  -0.3712026 
Kurtosis:  1.903942<jupyter_text>The values are fairly symmetrical, very slightly skewed to the left and platykurtic.<jupyter_code># plot a histogram to visualize the distribution of values in 'daily_time_spent_on_site' column

options(repr.plot.width = 8, repr.plot.height = 6)
p = data %>% ggplot(aes(x = daily_time_spent_on_site ))

p + geom_histogram(color="lightgray", fill="darkblue", binwidth = 10) +
    labs(title = "Distribution of Daily Time Spent on Site", x = "Time spent on site", y = "Frequency") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20))
# compute the quantiles and interquartile range of the values in the 'daily_time_spent_on_site' column 
quantile(data$daily_time_spent_on_site)
cat('The interquartile range of daily time spent on site is:',IQR(data$daily_time_spent_on_site))<jupyter_output><empty_output><jupyter_text>25% of the individuals spend less than 51.36 minutes on site and 75% of them spend less than 78.55 minutes on site  Age<jupyter_code># compute the variance and standard deviation of the values in 'age' column
cat('The variance of age is:',var(data$age), '\n')
cat('The standard deviation of age is:',sd(data$age))<jupyter_output>The variance of age is: 77.18611 
The standard deviation of age is: 8.785562<jupyter_text>The standard deviation shows that the values are not so spread out from the mean and the variance shows that the degree to which each value differs from the mean is low.<jupyter_code># compute the range, and the minimum and maximum values in 'age' column
cat("The minimum age of an is:", min(data$age),'years', '\n')
cat("The maximum age of is:", max(data$age),'years', '\n')
cat('The difference between the minimum and maximum ages is:', (max(data$age)-min(data$age)),'years')
# compute the skewness and kurtosis of values in the 'age' column
cat('The following are skewness and kurtosis of age', '\n')
cat("Skewness: ", skewness(data$age), '\n')
cat("Kurtosis: ", kurtosis(data$age), '\n')<jupyter_output>The following are skewness and kurtosis of age 
Skewness:  0.4784227 
Kurtosis:  2.595482<jupyter_text>The values are fairly symmetrical, very slightly skewed to the right and platykurtic<jupyter_code># plot a histogram to visualize the distribution of values in 'age' column

options(repr.plot.width = 8, repr.plot.height = 6)
p = data %>% ggplot(aes(x = age ))

p + geom_histogram(color="lightgray", fill="darkblue", binwidth = 10) +
    labs(title = "Distribution of Age", x = "Age", y = "Frequency") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20))
# compute the quantiles and interquartile range of the values in the 'age' column 
quantile(data$age)
cat('The interquartile range of age is:',IQR(data$age))<jupyter_output><empty_output><jupyter_text>25% of the individuals are below 29 years while 75% of them are below 42 years  Area income<jupyter_code># compute the variance and standard deviation of the values in 'area_income' column
cat('The variance of area income is:',var(data$area_income), '\n')
cat('The standard deviation of area income is:',sd(data$area_income))<jupyter_output>The variance of area income is: 179952406 
The standard deviation of area income is: 13414.63<jupyter_text>The standard deviation shows that the values are spread out from the mean and the variance shows that the degree to which each value differs from the mean is very high.<jupyter_code># compute the range, and the minimum and maximum values in 'area_income' column
cat("The minimum area income of is:", min(data$area_income),'Shillings', '\n')
cat("The maximum area income is:", max(data$area_income),'Shillings', '\n')
cat('The range between the minimum and maximum area incomes is:', (max(data$area_income)-min(data$area_income)),'Shillings')
# compute the skewness and kurtosis of values in the 'area_income' column
cat('The following are skewness and kurtosis of area income', '\n')
cat("Skewness: ", skewness(data$area_income), '\n')
cat("Kurtosis: ", kurtosis(data$area_income), '\n')<jupyter_output>The following are skewness and kurtosis of area income 
Skewness:  -0.6493967 
Kurtosis:  2.894694<jupyter_text>The values are moderately skewed to the left and platykurtic<jupyter_code># plot a histogram to visualize the distribution of values in 'area_income' column

options(repr.plot.width = 8, repr.plot.height = 6)
p = data %>% ggplot(aes(x = area_income ))

p + geom_histogram(color="lightgray", fill="darkblue", binwidth = 10000) +
    labs(title = "Distribution of Area Income", x = "Area Income", y = "Frequency") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20))
# compute the quantiles and interquartile range of the values in the 'area_income' column 
quantile(data$area_income)
cat('The interquartile range of area income is:',IQR(data$area_income))<jupyter_output><empty_output><jupyter_text>25% of the individuals have an area income of less than 47,032 shillings 75% of the individuals have an area income of less than 65,471 shillings   Daily internet usage<jupyter_code># compute the variance and standard deviation of the values in 'daily_time_spent_on_site' column
cat('The variance of daily internet usage is:',var(data$daily_internet_usage), '\n')
cat('The standard deviation of daily internet usage is:',sd(data$daily_internet_usage))<jupyter_output>The variance of daily internet usage is: 1927.415 
The standard deviation of daily internet usage is: 43.90234<jupyter_text>The standard deviation shows that the values are a bit spread out from the mean and the variance shows that the degree to which each value differs from the mean is high.<jupyter_code># compute the range, and the minimum and maximum values in 'daily_internet_usage' column
cat("The minimum daily internet usage of an is:", min(data$daily_internet_usage),'minutes', '\n')
cat("The maximum daily internet usage of is:", max(data$daily_internet_usage),'minutes', '\n')
cat('The difference between the minimum and maximum internet usage is:', (max(data$daily_internet_usage)-min(data$daily_internet_usage)),'minutes')
# compute the skewness and kurtosis of values in the 'daily_internet_usage' column
cat('The following are skewness and kurtosis of daily internet usage', '\n')
cat("Skewness: ", skewness(data$daily_internet_usage), '\n')
cat("Kurtosis: ", kurtosis(data$daily_internet_usage), '\n')<jupyter_output>The following are skewness and kurtosis of daily internet usage 
Skewness:  -0.03348703 
Kurtosis:  1.727701<jupyter_text>The values are fairly symmetrical and platykurtic<jupyter_code># plot a histogram to visualize the distribution of values in 'daily_internet_usage' column

options(repr.plot.width = 8, repr.plot.height = 6)
p = data %>% ggplot(aes(x = daily_internet_usage))

p + geom_histogram(color="lightgray", fill="darkblue", binwidth = 20) +
    labs(title = "Distribution of Daily Internet Usage", x = "Daily internet usage", y = "Frequency") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20))
# compute the quantiles and interquartile range of the values in the 'daily_internet_usage' column 
quantile(data$daily_internet_usage)
cat('The interquartile range of age is:',IQR(data$daily_internet_usage))<jupyter_output><empty_output><jupyter_text>25% of the individuals spend less than 138.83 minutes online and 75% of the individuals spend less than 218.79 minutes online.  Categorical variables<jupyter_code># plot a pie chart to visualize the proportion of values in the 'clicked_on_ad' column
data.clicked = data %>% 
  filter(clicked_on_ad != "NA") %>% 
  group_by(clicked_on_ad) %>% 
  count() %>% 
  ungroup()%>% 
  arrange(desc(clicked_on_ad)) %>%
  mutate(percentage = round(n/sum(n),4)*100,
         lab.pos = cumsum(percentage)-.5*percentage)
ggplot(data = data.clicked, 
       aes(x = "", y = percentage, fill = clicked_on_ad))+
  geom_bar(stat = "identity")+
  coord_polar("y", start = 200) +
  geom_text( aes(y = lab.pos, label = paste(percentage,"%", sep = "")), col = "black") +
  theme_void() + scale_fill_brewer(palette = "Pastel2") + labs(title= 'Pie Chart for Clicked on Ad') + 
  theme(plot.title = element_text(hjust = 0.5, size = 24))

# plot a pie chart to visualize the proportion of values in the 'gender' column
data.gender = data %>% 
  filter(gender != "NA") %>% 
  group_by(gender) %>% 
  count() %>% 
  ungroup()%>% 
  arrange(desc(gender)) %>%
  mutate(percentage = round(n/sum(n),4)*100,
         lab.pos = cumsum(percentage)-.5*percentage)
ggplot(data = data.gender, 
       aes(x = "", y = percentage, fill = gender))+
  geom_bar(stat = "identity")+
  coord_polar("y", start = 200) +
  geom_text(aes(y = lab.pos, label = paste(percentage,"%", sep = "")), col = "black") +
  theme_void() + scale_fill_brewer(palette = "Pastel1") + labs(title= 'Pie Chart for Gender') + 
  theme(plot.title = element_text(hjust = 0.5, size = 24))

# plot a bar chart to visualize the proportion of values in 'part_of_month' column
ggplot(data, aes(part_of_month)) + 
        geom_bar(aes(y = (..count..)/sum(..count..)), fill = "#FF6666") + 
        scale_y_continuous(labels=scales::percent) +
        labs(title= 'Proportions of Parts of Months', x='Part of month', y="Proportion") + 
        theme(axis.title = element_text(size = 18),
              axis.text = element_text(size=16),
              plot.title = element_text(hjust = 0.5, size = 24))
# create a frequency table to get the actual figures of frequencies of parts of month using tabyl function
tabyl(data$part_of_month, sort = TRUE)<jupyter_output><empty_output><jupyter_text>More individuals used the internet early and mid month than late in the month<jupyter_code># plot a bar chart to visualize the proportion of values in 'part_of_day' column
ggplot(data, aes(part_of_day)) + 
        geom_bar(aes(y = (..count..)/sum(..count..)), fill = "#FF6666") + 
        scale_y_continuous(labels=scales::percent) +
        labs(title= 'Proportions of Parts of Days', x='Part of day', y="Proportion") + 
        theme(axis.title = element_text(size = 18),
              axis.text = element_text(size=16),
              plot.title = element_text(hjust = 0.5, size = 24), axis.text.x = element_text(angle = 90))
# create a frequency table to get the actual figures of frequencies of parts of day using tabyl function
tabyl(data$part_of_day, sort =TRUE,)<jupyter_output><empty_output><jupyter_text>More individuals visited the site early in the morning than the rest of the day while fewer individuals visited the site late in the night.<jupyter_code># plot a bar chart to visualize the proportion of values in 'month' column
ggplot(data, aes(month)) + 
        geom_bar(aes(y = (..count..)/sum(..count..)), fill = "#FF6666") + 
        scale_y_continuous(labels=scales::percent) +
        labs(title= 'Proportions of Months', x='Month', y="Proportion") + 
        theme(axis.title = element_text(size = 18),
              axis.text = element_text(size=16),
              plot.title = element_text(hjust = 0.5, size = 24))
# create a frequency table to get the actual figures of frequencies of months using tabyl() function
tabyl(data$month, sort =TRUE)<jupyter_output><empty_output><jupyter_text>February had the most number of visits while July had the least number of visits<jupyter_code># create a frequency table to get the actual figures of frequencies of countries using count function
data %>% count(country, sort = TRUE)<jupyter_output><empty_output><jupyter_text>Czech Republic and France had the most number of visitors while Aruba and 13 other countries had the least number of visitors  Bivariate analysis  Bivariate analysis will help us establish the relationship between the variables, more so, the relationship between the varibles and the chances of clicking on the ads  Recommendation for working on research question  In order to effectively perform bivariate analysis while working on the research question, one should analyse the different variables against the 'clicked_on_ad' variable in order to identify the individuals who are likely to click on the ads<jupyter_code># plot a stacked bar chart to visualize the relationship between gender and clicking on the ad
ggplot(data, 
       aes(x = gender, 
           fill = clicked_on_ad)) + 
  geom_bar(position = "fill") +
    labs(title = "Clicking on Ad vs Gender", x = "Gender", y = "Proportion") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20))
# plot a stacked bar chart to visualize the relationship between month and clicking on the ad
ggplot(data, 
       aes(x = month, 
           fill = clicked_on_ad)) +  
  geom_bar(position = "fill") +
    labs(title = "Clicking on Ad vs Month", x = "Month", y = "Proportion") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20))
# plot a stacked bar chart to visualize the relationship between part of month and clicking on the ad
ggplot(data, 
       aes(x = part_of_month, 
           fill = clicked_on_ad)) + 
  geom_bar(position = "fill") +
    labs(title = "Clicking on Ad vs Part of Month", x = "Part of month", y = "Proportion") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20))
# plot a stacked bar chart to visualize the relationship between part of day and clicking on the ad
ggplot(data, 
       aes(x = part_of_day, 
           fill = clicked_on_ad)) + 
  geom_bar(position = "fill") +
    labs(title = "Clicking on Ad vs Part of Day", x = "Part of day", y = "Proportion") +
    theme(axis.title = element_text(size = 20),
          axis.text = element_text(size=16),
          plot.title = element_text(hjust = 0.5, size = 20), 
          axis.text.x = element_text(angle = 90))
# plot a boxplot to visualize the relationship between daily time spent on site and clicking on the ad
boxplot(data$daily_time_spent_on_site ~ data$clicked_on_ad, col='darkblue', main="Daily Time Spent on Site vs Clicking on Ad", xlab = "Clicked on ad", ylab = "Daily time spent on site", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)
# compute the means of daily time spent on site per group of ad clicking
aggregate(data$daily_time_spent_on_site, list(data$clicked_on_ad), mean) 
# plot a boxplot to visualize the relationship between age and clicking on the ad
boxplot(data$age ~ data$clicked_on_ad, col='darkblue', main="Age vs Clicking on Ad", xlab = "Clicked on ad", ylab = "Age", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)
# compute the means of age per group of ad clicking
aggregate(data$age, list(data$clicked_on_ad), mean)
# plot a boxplot to visualize the relationship between area income and clicking on the ad
boxplot(data$area_income ~ data$clicked_on_ad, col='darkblue', main="Area Income vs Clicking on Ad", xlab = "Clicked on ad", ylab = "Area income", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)
# compute the means of area income per group of ad clicking
aggregate(data$area_income, list(data$clicked_on_ad), mean) 
# plot a boxplot to visualize the relationship between daily time spent on site and clicking on the ad
boxplot(data$daily_internet_usage ~ data$clicked_on_ad, col='darkblue', main="Daily Internet Usage vs Clicking on Ad", xlab = "Clicked on ad", ylab = "Daily internet usage", boxwex=0.4, cex.main=2, cex.lab=1.5, cex.axis=1.2)
# compute the means of daily internet usage per group of ad clicking
aggregate(data$daily_internet_usage, list(data$clicked_on_ad), median) 
# Pearson correlation analysis

# identify numerical variables in the dataframe
num_col <- unlist(lapply(data, is.numeric))

# select and subset the numerical variables
data_num <- subset(data, select=num_col) 

# compute the correlations between the variables and display the correlation matrix
cor(data_num)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10732247635013771, 'fraction_numerical': 0.0433780385582565, 'mean_word_length': 4.0759762953958365, 'pattern_counts': {'":': 0, '<': 162, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '38', 'dir': 'jupyter-structured-clean-dedup', 'id': '601295', 'license': 'MIT', 'n_tokens_mistral': 11780, 'n_tokens_neox': 10262, 'n_words': 3432, 'path': 'Week_12_IP.ipynb', 'repo_name': 'WambuiKahuthu/MORINGA_CORE_WEEK12_EDA_R', 'size': '33404'}