#install.packages("eeptools")
#Cargamos la base y le asignamos un nombre
Amazon <- read.csv("data_set_amazon.csv")
#Analisis de los datos con los que contamos
names(Amazon)
## [1] "User.ID" "Name"
## [3] "Email.Address" "Username"
## [5] "Date.of.Birth" "Gender"
## [7] "Location" "Membership.Start.Date"
## [9] "Membership.End.Date" "Subscription.Plan"
## [11] "Payment.Information" "Renewal.Status"
## [13] "Usage.Frequency" "Purchase.History"
## [15] "Favorite.Genres" "Devices.Used"
## [17] "Engagement.Metrics" "Feedback.Ratings"
## [19] "Customer.Support.Interactions"
summary(Amazon)
## User.ID Name Email.Address Username
## Min. : 1.0 Length:2500 Length:2500 Length:2500
## 1st Qu.: 625.8 Class :character Class :character Class :character
## Median :1250.5 Mode :character Mode :character Mode :character
## Mean :1250.5
## 3rd Qu.:1875.2
## Max. :2500.0
## Date.of.Birth Gender Location Membership.Start.Date
## Length:2500 Length:2500 Length:2500 Length:2500
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Membership.End.Date Subscription.Plan Payment.Information Renewal.Status
## Length:2500 Length:2500 Length:2500 Length:2500
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Usage.Frequency Purchase.History Favorite.Genres Devices.Used
## Length:2500 Length:2500 Length:2500 Length:2500
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Engagement.Metrics Feedback.Ratings Customer.Support.Interactions
## Length:2500 Min. :3.000 Min. : 0.000
## Class :character 1st Qu.:3.500 1st Qu.: 2.000
## Mode :character Median :4.000 Median : 5.000
## Mean :4.005 Mean : 4.952
## 3rd Qu.:4.500 3rd Qu.: 8.000
## Max. :5.000 Max. :10.000
head(Amazon)
## User.ID Name Email.Address Username
## 1 1 Ronald Murphy williamholland@example.com williamholland
## 2 2 Scott Allen scott22@example.org scott22
## 3 3 Jonathan Parrish brooke16@example.org brooke16
## 4 4 Megan Williams elizabeth31@example.net elizabeth31
## 5 5 Kathryn Brown pattersonalexandra@example.org pattersonalexandra
## 6 6 Sandra Cox gparks@example.org gparks
## Date.of.Birth Gender Location Membership.Start.Date Membership.End.Date
## 1 1953-06-03 Male Rebeccachester 2024-01-15 2025-01-14
## 2 1978-07-08 Male Mcphersonview 2024-01-07 2025-01-06
## 3 1994-12-06 Female Youngfort 2024-04-13 2025-04-13
## 4 1964-12-22 Female Feliciashire 2024-01-24 2025-01-23
## 5 1961-06-04 Male Port Deborah 2024-02-14 2025-02-13
## 6 1954-09-19 Female Lake Johnathan 2024-01-15 2025-01-14
## Subscription.Plan Payment.Information Renewal.Status Usage.Frequency
## 1 Annual Mastercard Manual Regular
## 2 Monthly Visa Manual Regular
## 3 Monthly Mastercard Manual Regular
## 4 Monthly Amex Auto-renew Regular
## 5 Annual Visa Auto-renew Frequent
## 6 Monthly Amex Manual Occasional
## Purchase.History Favorite.Genres Devices.Used Engagement.Metrics
## 1 Electronics Documentary Smart TV Medium
## 2 Electronics Horror Smartphone Medium
## 3 Books Comedy Smart TV Low
## 4 Electronics Documentary Smart TV High
## 5 Clothing Drama Smart TV Low
## 6 Books Action Tablet Low
## Feedback.Ratings Customer.Support.Interactions
## 1 3.6 3
## 2 3.8 7
## 3 3.3 8
## 4 3.3 7
## 5 4.3 1
## 6 3.8 2
Hipotesis. Los usuarios de entre 20 y 50 años que prefieren géneros de entretenimiento (Favorite.Genres) como comedy y action tienden a tener un nivel medio a alto de compromiso con el servicio (Engagement.Metrics), y este compromiso aumenta con la edad.
Primero vamos a transformar la variable “Date.of.Birth” a edad, me permitirá una análisis exploratorio más sencillo
# Nos aseguramos de que la columna "Date.of.Birth" fue transformado a Date
Amazon <- Amazon %>%
mutate(Date.of.Birth = as.Date(`Date.of.Birth`, format = "%Y-%m-%d"))
# Vamos a crear una base llamada AmazonE donde incluyamos una nueva variable que es Edad
AmazonE <- Amazon %>%
mutate(edad = as.integer(floor(interval(Date.of.Birth, Sys.Date()) / years(1))))
head(AmazonE)
## User.ID Name Email.Address Username
## 1 1 Ronald Murphy williamholland@example.com williamholland
## 2 2 Scott Allen scott22@example.org scott22
## 3 3 Jonathan Parrish brooke16@example.org brooke16
## 4 4 Megan Williams elizabeth31@example.net elizabeth31
## 5 5 Kathryn Brown pattersonalexandra@example.org pattersonalexandra
## 6 6 Sandra Cox gparks@example.org gparks
## Date.of.Birth Gender Location Membership.Start.Date Membership.End.Date
## 1 1953-06-03 Male Rebeccachester 2024-01-15 2025-01-14
## 2 1978-07-08 Male Mcphersonview 2024-01-07 2025-01-06
## 3 1994-12-06 Female Youngfort 2024-04-13 2025-04-13
## 4 1964-12-22 Female Feliciashire 2024-01-24 2025-01-23
## 5 1961-06-04 Male Port Deborah 2024-02-14 2025-02-13
## 6 1954-09-19 Female Lake Johnathan 2024-01-15 2025-01-14
## Subscription.Plan Payment.Information Renewal.Status Usage.Frequency
## 1 Annual Mastercard Manual Regular
## 2 Monthly Visa Manual Regular
## 3 Monthly Mastercard Manual Regular
## 4 Monthly Amex Auto-renew Regular
## 5 Annual Visa Auto-renew Frequent
## 6 Monthly Amex Manual Occasional
## Purchase.History Favorite.Genres Devices.Used Engagement.Metrics
## 1 Electronics Documentary Smart TV Medium
## 2 Electronics Horror Smartphone Medium
## 3 Books Comedy Smart TV Low
## 4 Electronics Documentary Smart TV High
## 5 Clothing Drama Smart TV Low
## 6 Books Action Tablet Low
## Feedback.Ratings Customer.Support.Interactions edad
## 1 3.6 3 71
## 2 3.8 7 45
## 3 3.3 8 29
## 4 3.3 7 59
## 5 4.3 1 63
## 6 3.8 2 69
summary(AmazonE)
## User.ID Name Email.Address Username
## Min. : 1.0 Length:2500 Length:2500 Length:2500
## 1st Qu.: 625.8 Class :character Class :character Class :character
## Median :1250.5 Mode :character Mode :character Mode :character
## Mean :1250.5
## 3rd Qu.:1875.2
## Max. :2500.0
## Date.of.Birth Gender Location
## Min. :1933-04-26 Length:2500 Length:2500
## 1st Qu.:1951-04-30 Class :character Class :character
## Median :1969-12-07 Mode :character Mode :character
## Mean :1969-10-10
## 3rd Qu.:1988-03-28
## Max. :2006-04-11
## Membership.Start.Date Membership.End.Date Subscription.Plan
## Length:2500 Length:2500 Length:2500
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## Payment.Information Renewal.Status Usage.Frequency Purchase.History
## Length:2500 Length:2500 Length:2500 Length:2500
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Favorite.Genres Devices.Used Engagement.Metrics Feedback.Ratings
## Length:2500 Length:2500 Length:2500 Min. :3.000
## Class :character Class :character Class :character 1st Qu.:3.500
## Mode :character Mode :character Mode :character Median :4.000
## Mean :4.005
## 3rd Qu.:4.500
## Max. :5.000
## Customer.Support.Interactions edad
## Min. : 0.000 Min. :18.00
## 1st Qu.: 2.000 1st Qu.:36.00
## Median : 5.000 Median :54.00
## Mean : 4.952 Mean :54.21
## 3rd Qu.: 8.000 3rd Qu.:73.00
## Max. :10.000 Max. :91.00
A la variable “Engagement.Metrics” también la vamos a transformar de caracteres a valores numéricos
AmazonEng <- AmazonE %>%
mutate(Engagement.Metrics = factor(Engagement.Metrics, levels = c("Low", "Medium", "High"))) %>%
mutate(Engagement.Metrics = as.numeric(Engagement.Metrics))
Ya checamos las variables con las que contamos, se estableció la hipótesis y se limpio la base, sin embargo, para conocer un poco del panorama global con el que vamos a trabajar, se tomó la decisión de ver el comportamiento de la edad respecto a las preferencia de entretenimiento, siendo aún más especifíco para ver el comportamiento, se hizo el análisis por hombrres y mujeres. Para ello usamos filtrados, mutate, conteo, y para ver el comportamiento visualmente se elaboraron 2 gráficos.
## Filtramos datos para mujeres y creamos Edad_GrupM (Agrupamos por edades de 10 en 10, de los 18 a los 90)
Filtro_Mujeres <- AmazonEng %>%
filter(Gender == "Female") %>%
mutate(Edad_GrupM = cut(edad, breaks = seq(18, 90, by = 10),
labels = c("18-20", "21-30", "31-40", "41-50", "51-60", "61-70", "71-80"),
include.lowest = TRUE))
## Hacemos un conteo de preferencias de entretenimiento por grupo de edad en mujeres
Conteo_Prefe_Mujer <- Filtro_Mujeres %>%
group_by(Edad_GrupM, Favorite.Genres) %>%
summarise(Count = n()) %>%
ungroup() %>%
arrange(Edad_GrupM, Favorite.Genres)
## `summarise()` has grouped output by 'Edad_GrupM'. You can override using the
## `.groups` argument.
## Gráfico de "Preferencia de entretenimiento por edad para mujeres"
ggplot(Conteo_Prefe_Mujer, aes(x = Edad_GrupM, y = Count, color = Favorite.Genres, group = Favorite.Genres)) +
geom_line(size = 1) +
geom_point(size = 2) +
labs(title = "Preferencias de Entretenimiento por Edad (Mujeres)",
x = "Edad",
y = "Cantidad de Usuarios",
color = "Género de Entretenimiento") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Filtramos datos para hombres y creamos Edad_GrupH (Agrupamos por edades de 10 en 10, de los 18 a los 90)
Filtro_Hombres <- AmazonEng %>%
filter(Gender == "Male") %>%
mutate(Edad_GrupH = cut(edad, breaks = seq(18, 90, by = 10),
labels = c("18-20", "21-30", "31-40", "41-50", "51-60", "61-70", "71-80"),
include.lowest = TRUE))
## Hacemos un conteo de preferencias de entretenimiento por grupo de edad en hombres
Conteo_Prefe_Hombre <- Filtro_Hombres %>%
group_by(Edad_GrupH, Favorite.Genres) %>%
summarise(Count = n()) %>%
ungroup() %>%
arrange(Edad_GrupH, Favorite.Genres)
## `summarise()` has grouped output by 'Edad_GrupH'. You can override using the
## `.groups` argument.
## Gráfico "Preferencia de entretenimiento por edad para hombres"
ggplot(Conteo_Prefe_Hombre, aes(x = Edad_GrupH, y = Count, color = Favorite.Genres, group = Favorite.Genres)) +
geom_line(size = 1) +
geom_point(size = 2) +
labs(title = "Preferencias de Entretenimiento por Edad (Hombres)",
x = "Edad",
y = "Cantidad de Usuarios",
color = "Género de Entretenimiento") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
## Filtramos datos general (sin distinción de hombre o mujer) y creamos Edad_Grupal (Agrupamos por edades de 10 en 10, de los 18 a los 90)
Filtro_General <- AmazonEng %>%
mutate(Edad_Grupal = cut(edad, breaks = seq(18, 90, by = 10),
labels = c("18-20", "21-30", "31-40", "41-50", "51-60", "61-70", "71-80"),
include.lowest = TRUE))
## Hacemos un conteo de preferencias de entretenimiento por grupo de edad
Conteo_Prefe_General <- Filtro_General %>%
group_by(Edad_Grupal, Favorite.Genres) %>%
summarise(Count = n()) %>%
ungroup() %>%
arrange(Edad_Grupal, Favorite.Genres)
## `summarise()` has grouped output by 'Edad_Grupal'. You can override using the
## `.groups` argument.
## Gráfico "Preferencia de entretenimiento por edad"
ggplot(Conteo_Prefe_General, aes(x = Edad_Grupal, y = Count, color = Favorite.Genres, Favorite.Genres)) +
geom_line(size = 1) +
geom_point(size = 2) +
labs(title = "Preferencia de Entretenimiento por Edades",
x = "Edad",
y = "Cantidad de Usuarios",
color = "Género de Entretenimiento") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
## `geom_line()`: Each group consists of only one observation.
## i Do you need to adjust the group aesthetic?
Haciendo un análisis subjetivo, se observa que las Mujeres en el rango de 21 a 50 años el consumo es preferencial en comedy, romance y action, por su parte, los Hombres de 21 a 50 años muestran mayor preferencia a horror y documentary. En el gráfico de entretenimiento por edades, presenta que la población general de estudio (21 a 50 años) tiene mayor preferencia por comedy, romance y documentary.
#Como nuestros datos de interes son personas entre 20 y 50 años, cuyo perfil de interes es comedy y action, vamos a limpiar nuestra base, obteniendo así la base limpia llamada “Pre_Amazon20_50”
Pre_Amazon20_50 <- AmazonEng %>%
select(Favorite.Genres, edad, Engagement.Metrics,Customer.Support.Interactions, Gender) %>%
filter(edad >= 20 & edad <= 50, Favorite.Genres == c("Action", "Comedy")) %>%
group_by(edad, Favorite.Genres)
print(Pre_Amazon20_50)
## # A tibble: 165 x 5
## # Groups: edad, Favorite.Genres [57]
## Favorite.Genres edad Engagement.Metrics Customer.Support.Interactions Gender
## <chr> <int> <dbl> <int> <chr>
## 1 Action 42 2 0 Female
## 2 Comedy 37 3 7 Female
## 3 Comedy 47 2 9 Male
## 4 Comedy 32 3 10 Female
## 5 Comedy 29 1 6 Female
## 6 Comedy 33 2 2 Male
## 7 Comedy 50 3 10 Male
## 8 Action 45 1 6 Female
## 9 Comedy 39 2 9 Male
## 10 Action 20 1 0 Male
## # i 155 more rows
summary(Pre_Amazon20_50)
## Favorite.Genres edad Engagement.Metrics
## Length:165 Min. :20.00 Min. :1.000
## Class :character 1st Qu.:29.00 1st Qu.:1.000
## Mode :character Median :36.00 Median :2.000
## Mean :35.64 Mean :2.042
## 3rd Qu.:43.00 3rd Qu.:3.000
## Max. :50.00 Max. :3.000
## Customer.Support.Interactions Gender
## Min. : 0.000 Length:165
## 1st Qu.: 2.000 Class :character
## Median : 5.000 Mode :character
## Mean : 4.976
## 3rd Qu.: 8.000
## Max. :10.000
Regr_Lineal <- Pre_Amazon20_50 %>%
filter(edad >= 20 & edad <= 50) %>% na.omit()
modelo <- lm(Engagement.Metrics ~ edad, data = Regr_Lineal)
summary(modelo)
##
## Call:
## lm(formula = Engagement.Metrics ~ edad, data = Regr_Lineal)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.0863 -1.0077 -0.0386 0.9361 0.9979
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.142444 0.256495 8.353 2.75e-14 ***
## edad -0.002807 0.006990 -0.402 0.689
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7856 on 163 degrees of freedom
## Multiple R-squared: 0.0009882, Adjusted R-squared: -0.005141
## F-statistic: 0.1612 on 1 and 163 DF, p-value: 0.6886
# Visualización del modelo
ggplot(Regr_Lineal, aes(x = edad, y = Engagement.Metrics)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Regresión Lineal: Compromiso con el Servicio según Edad",
x = "Edad",
y = "Engagement Metrics") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
Conclusión.
Con los gráficos obtenidos y el análisis realizado, se puede decir que los usuarios de entre 20 y 50 años que prefieren géneros de entretenimiento como comedy y action tienden a tener un nivel medio a alto de compromiso con el servicio, sin embargo, esta tendencia del compromiso no aumenta con la edad. Esto se puede deber a diferentes factores ajenos a la plataforma.