Sprint 2 Adicional

Analítica descriptiva en un reto en el ámbito de las FINANZAS

Fuente de datos

Objetivo de la actividad

Con el objetivo de ampliar las aplicaciones prácticas en analítica descriptiva sobre la temática vista en la clase 2, se propone realizar este sprint opcional sobre un conjunto de datos que encontramos en Kaggle en el ámbito de las FINANZAS.

Preparacion del entorno de trabajo

Se cargan las librerias y los datos a trabajar.

# Cargar las librerias 
# Librerías para manipulación y modelado de datos
library(tidyr)        # Manipulación de datos
library(tidyverse)    # Conjunto de paquetes para manipulación de datos
library(dplyr)        # Manipulación de datos con funciones verbosas
library(ggplot2)      # Creación de gráficos con ggplot2
library(plotly)       # Gráficos interactivos
library(readr)        # Lectura de datos

# Librerías para estadísticas descriptivas y exploratorias
library(pastecs)      # Estadísticas descriptivas
library(Hmisc)        # Herramientas y procedimientos misceláneos
library(expss)        # Análisis de datos categóricos

# Cargar los datos
data <- read_csv("/Users/anadinezio/Downloads/ADP_Clase 2/Finance_data.csv")

Exploracion de los datos con analitica descriptiva basica

# Analitica exploratoria basica
# View(data). lo comento solo por propositos de markdown
summary(data)
##     gender               age        Investment_Avenues  Mutual_Funds 
##  Length:40          Min.   :21.00   Length:40          Min.   :1.00  
##  Class :character   1st Qu.:25.75   Class :character   1st Qu.:2.00  
##  Mode  :character   Median :27.00   Mode  :character   Median :2.00  
##                     Mean   :27.80                      Mean   :2.55  
##                     3rd Qu.:30.00                      3rd Qu.:3.00  
##                     Max.   :35.00                      Max.   :7.00  
##  Equity_Market     Debentures   Government_Bonds Fixed_Deposits 
##  Min.   :1.000   Min.   :1.00   Min.   :1.00     Min.   :1.000  
##  1st Qu.:3.000   1st Qu.:5.00   1st Qu.:4.00     1st Qu.:2.750  
##  Median :4.000   Median :6.50   Median :5.00     Median :3.500  
##  Mean   :3.475   Mean   :5.75   Mean   :4.65     Mean   :3.575  
##  3rd Qu.:4.000   3rd Qu.:7.00   3rd Qu.:5.00     3rd Qu.:5.000  
##  Max.   :6.000   Max.   :7.00   Max.   :7.00     Max.   :7.000  
##       PPF             Gold       Stock_Marktet         Factor         
##  Min.   :1.000   Min.   :2.000   Length:40          Length:40         
##  1st Qu.:1.000   1st Qu.:6.000   Class :character   Class :character  
##  Median :1.000   Median :6.000   Mode  :character   Mode  :character  
##  Mean   :2.025   Mean   :5.975                                        
##  3rd Qu.:2.250   3rd Qu.:7.000                                        
##  Max.   :6.000   Max.   :7.000                                        
##   Objective           Purpose            Duration         Invest_Monitor    
##  Length:40          Length:40          Length:40          Length:40         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     Expect             Avenue          What are your savings objectives?
##  Length:40          Length:40          Length:40                        
##  Class :character   Class :character   Class :character                 
##  Mode  :character   Mode  :character   Mode  :character                 
##                                                                         
##                                                                         
##                                                                         
##  Reason_Equity      Reason_Mutual      Reason_Bonds        Reason_FD        
##  Length:40          Length:40          Length:40          Length:40         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     Source         
##  Length:40         
##  Class :character  
##  Mode  :character  
##                    
##                    
## 
print(data)
## # A tibble: 40 × 24
##    gender   age Investment_Avenues Mutual_Funds Equity_Market Debentures
##    <chr>  <dbl> <chr>                     <dbl>         <dbl>      <dbl>
##  1 Female    34 Yes                           1             2          5
##  2 Female    23 Yes                           4             3          2
##  3 Male      30 Yes                           3             6          4
##  4 Male      22 Yes                           2             1          3
##  5 Female    24 No                            2             1          3
##  6 Female    24 No                            7             5          4
##  7 Female    27 Yes                           3             6          4
##  8 Male      21 Yes                           2             3          7
##  9 Male      35 Yes                           2             4          7
## 10 Male      31 Yes                           1             3          7
## # ℹ 30 more rows
## # ℹ 18 more variables: Government_Bonds <dbl>, Fixed_Deposits <dbl>, PPF <dbl>,
## #   Gold <dbl>, Stock_Marktet <chr>, Factor <chr>, Objective <chr>,
## #   Purpose <chr>, Duration <chr>, Invest_Monitor <chr>, Expect <chr>,
## #   Avenue <chr>, `What are your savings objectives?` <chr>,
## #   Reason_Equity <chr>, Reason_Mutual <chr>, Reason_Bonds <chr>,
## #   Reason_FD <chr>, Source <chr>
head(data)
## # A tibble: 6 × 24
##   gender   age Investment_Avenues Mutual_Funds Equity_Market Debentures
##   <chr>  <dbl> <chr>                     <dbl>         <dbl>      <dbl>
## 1 Female    34 Yes                           1             2          5
## 2 Female    23 Yes                           4             3          2
## 3 Male      30 Yes                           3             6          4
## 4 Male      22 Yes                           2             1          3
## 5 Female    24 No                            2             1          3
## 6 Female    24 No                            7             5          4
## # ℹ 18 more variables: Government_Bonds <dbl>, Fixed_Deposits <dbl>, PPF <dbl>,
## #   Gold <dbl>, Stock_Marktet <chr>, Factor <chr>, Objective <chr>,
## #   Purpose <chr>, Duration <chr>, Invest_Monitor <chr>, Expect <chr>,
## #   Avenue <chr>, `What are your savings objectives?` <chr>,
## #   Reason_Equity <chr>, Reason_Mutual <chr>, Reason_Bonds <chr>,
## #   Reason_FD <chr>, Source <chr>
tail(data)
## # A tibble: 6 × 24
##   gender   age Investment_Avenues Mutual_Funds Equity_Market Debentures
##   <chr>  <dbl> <chr>                     <dbl>         <dbl>      <dbl>
## 1 Male      27 Yes                           2             3          6
## 2 Male      30 Yes                           1             4          6
## 3 Male      30 Yes                           2             4          7
## 4 Male      25 Yes                           5             4          7
## 5 Male      31 Yes                           2             4          7
## 6 Male      29 Yes                           4             3          5
## # ℹ 18 more variables: Government_Bonds <dbl>, Fixed_Deposits <dbl>, PPF <dbl>,
## #   Gold <dbl>, Stock_Marktet <chr>, Factor <chr>, Objective <chr>,
## #   Purpose <chr>, Duration <chr>, Invest_Monitor <chr>, Expect <chr>,
## #   Avenue <chr>, `What are your savings objectives?` <chr>,
## #   Reason_Equity <chr>, Reason_Mutual <chr>, Reason_Bonds <chr>,
## #   Reason_FD <chr>, Source <chr>
str(data)
## spc_tbl_ [40 × 24] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ gender                           : chr [1:40] "Female" "Female" "Male" "Male" ...
##  $ age                              : num [1:40] 34 23 30 22 24 24 27 21 35 31 ...
##  $ Investment_Avenues               : chr [1:40] "Yes" "Yes" "Yes" "Yes" ...
##  $ Mutual_Funds                     : num [1:40] 1 4 3 2 2 7 3 2 2 1 ...
##  $ Equity_Market                    : num [1:40] 2 3 6 1 1 5 6 3 4 3 ...
##  $ Debentures                       : num [1:40] 5 2 4 3 3 4 4 7 7 7 ...
##  $ Government_Bonds                 : num [1:40] 3 1 2 7 6 6 2 4 5 4 ...
##  $ Fixed_Deposits                   : num [1:40] 7 5 5 6 4 3 5 6 3 5 ...
##  $ PPF                              : num [1:40] 6 6 1 4 5 1 1 1 1 2 ...
##  $ Gold                             : num [1:40] 4 7 7 5 7 2 7 5 6 6 ...
##  $ Stock_Marktet                    : chr [1:40] "Yes" "No" "Yes" "Yes" ...
##  $ Factor                           : chr [1:40] "Returns" "Locking Period" "Returns" "Returns" ...
##  $ Objective                        : chr [1:40] "Capital Appreciation" "Capital Appreciation" "Capital Appreciation" "Income" ...
##  $ Purpose                          : chr [1:40] "Wealth Creation" "Wealth Creation" "Wealth Creation" "Wealth Creation" ...
##  $ Duration                         : chr [1:40] "1-3 years" "More than 5 years" "3-5 years" "Less than 1 year" ...
##  $ Invest_Monitor                   : chr [1:40] "Monthly" "Weekly" "Daily" "Daily" ...
##  $ Expect                           : chr [1:40] "20%-30%" "20%-30%" "20%-30%" "10%-20%" ...
##  $ Avenue                           : chr [1:40] "Mutual Fund" "Mutual Fund" "Equity" "Equity" ...
##  $ What are your savings objectives?: chr [1:40] "Retirement Plan" "Health Care" "Retirement Plan" "Retirement Plan" ...
##  $ Reason_Equity                    : chr [1:40] "Capital Appreciation" "Dividend" "Capital Appreciation" "Dividend" ...
##  $ Reason_Mutual                    : chr [1:40] "Better Returns" "Better Returns" "Tax Benefits" "Fund Diversification" ...
##  $ Reason_Bonds                     : chr [1:40] "Safe Investment" "Safe Investment" "Assured Returns" "Tax Incentives" ...
##  $ Reason_FD                        : chr [1:40] "Fixed Returns" "High Interest Rates" "Fixed Returns" "High Interest Rates" ...
##  $ Source                           : chr [1:40] "Newspapers and Magazines" "Financial Consultants" "Television" "Internet" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   gender = col_character(),
##   ..   age = col_double(),
##   ..   Investment_Avenues = col_character(),
##   ..   Mutual_Funds = col_double(),
##   ..   Equity_Market = col_double(),
##   ..   Debentures = col_double(),
##   ..   Government_Bonds = col_double(),
##   ..   Fixed_Deposits = col_double(),
##   ..   PPF = col_double(),
##   ..   Gold = col_double(),
##   ..   Stock_Marktet = col_character(),
##   ..   Factor = col_character(),
##   ..   Objective = col_character(),
##   ..   Purpose = col_character(),
##   ..   Duration = col_character(),
##   ..   Invest_Monitor = col_character(),
##   ..   Expect = col_character(),
##   ..   Avenue = col_character(),
##   ..   `What are your savings objectives?` = col_character(),
##   ..   Reason_Equity = col_character(),
##   ..   Reason_Mutual = col_character(),
##   ..   Reason_Bonds = col_character(),
##   ..   Reason_FD = col_character(),
##   ..   Source = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
glimpse(data)
## Rows: 40
## Columns: 24
## $ gender                              <chr> "Female", "Female", "Male", "Male"…
## $ age                                 <dbl> 34, 23, 30, 22, 24, 24, 27, 21, 35…
## $ Investment_Avenues                  <chr> "Yes", "Yes", "Yes", "Yes", "No", …
## $ Mutual_Funds                        <dbl> 1, 4, 3, 2, 2, 7, 3, 2, 2, 1, 2, 2…
## $ Equity_Market                       <dbl> 2, 3, 6, 1, 1, 5, 6, 3, 4, 3, 4, 5…
## $ Debentures                          <dbl> 5, 2, 4, 3, 3, 4, 4, 7, 7, 7, 7, 7…
## $ Government_Bonds                    <dbl> 3, 1, 2, 7, 6, 6, 2, 4, 5, 4, 5, 6…
## $ Fixed_Deposits                      <dbl> 7, 5, 5, 6, 4, 3, 5, 6, 3, 5, 3, 3…
## $ PPF                                 <dbl> 6, 6, 1, 4, 5, 1, 1, 1, 1, 2, 1, 1…
## $ Gold                                <dbl> 4, 7, 7, 5, 7, 2, 7, 5, 6, 6, 6, 4…
## $ Stock_Marktet                       <chr> "Yes", "No", "Yes", "Yes", "No", "…
## $ Factor                              <chr> "Returns", "Locking Period", "Retu…
## $ Objective                           <chr> "Capital Appreciation", "Capital A…
## $ Purpose                             <chr> "Wealth Creation", "Wealth Creatio…
## $ Duration                            <chr> "1-3 years", "More than 5 years", …
## $ Invest_Monitor                      <chr> "Monthly", "Weekly", "Daily", "Dai…
## $ Expect                              <chr> "20%-30%", "20%-30%", "20%-30%", "…
## $ Avenue                              <chr> "Mutual Fund", "Mutual Fund", "Equ…
## $ `What are your savings objectives?` <chr> "Retirement Plan", "Health Care", …
## $ Reason_Equity                       <chr> "Capital Appreciation", "Dividend"…
## $ Reason_Mutual                       <chr> "Better Returns", "Better Returns"…
## $ Reason_Bonds                        <chr> "Safe Investment", "Safe Investmen…
## $ Reason_FD                           <chr> "Fixed Returns", "High Interest Ra…
## $ Source                              <chr> "Newspapers and Magazines", "Finan…
# Revisión de Nulos 
rowSums(is.na(data)) # filas
##  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [39] 0 0
colSums(is.na(data)) # columnas
##                            gender                               age 
##                                 0                                 0 
##                Investment_Avenues                      Mutual_Funds 
##                                 0                                 0 
##                     Equity_Market                        Debentures 
##                                 0                                 0 
##                  Government_Bonds                    Fixed_Deposits 
##                                 0                                 0 
##                               PPF                              Gold 
##                                 0                                 0 
##                     Stock_Marktet                            Factor 
##                                 0                                 0 
##                         Objective                           Purpose 
##                                 0                                 0 
##                          Duration                    Invest_Monitor 
##                                 0                                 0 
##                            Expect                            Avenue 
##                                 0                                 0 
## What are your savings objectives?                     Reason_Equity 
##                                 0                                 0 
##                     Reason_Mutual                      Reason_Bonds 
##                                 0                                 0 
##                         Reason_FD                            Source 
##                                 0                                 0
# Tablas simples
table(data$`gender`)
## 
## Female   Male 
##     15     25
table(data$`age`)
## 
## 21 22 23 24 25 26 27 28 29 30 31 32 34 35 
##  2  1  1  3  3  4  7  2  5  3  4  1  2  2
table(data$Mutual_Funds)
## 
##  1  2  3  4  5  7 
##  4 21  9  3  2  1
table(data$`Equity_Market`)
## 
##  1  2  3  4  5  6 
##  2  5 12 16  3  2
table(data$`Purpose`)
## 
##            Returns Savings for Future    Wealth Creation 
##                  2                  6                 32
table(data$Objective)
## 
## Capital Appreciation               Growth               Income 
##                   26                   11                    3
table(data$`Expect`)
## 
## 10%-20% 20%-30% 30%-40% 
##       3      32       5
table(data$`Source`)
## 
##    Financial Consultants                 Internet Newspapers and Magazines 
##                       16                        4                       14 
##               Television 
##                        6
table(data$Reason_Bonds)
## 
## Assured Returns Safe Investment  Tax Incentives 
##              26              13               1
# Histogramas de variables numericas
hist (data$`age`)

hist (data$`Mutual_Funds`)

hist (data$Equity_Market)

hist(data$Debentures)

hist(data$Government_Bonds)

hist(data$Fixed_Deposits)

hist(data$PPF)

hist(data$Gold)

Grafico de barras de variables categoricas

# Transformar variables categoricas
data$FACTOR <- as.factor(data$Factor) 
data$GENDER <- as.factor(data$gender)                       
data$STOCK_MARKET <- as.factor(data$Stock_Marktet)  
data$OBJECTIVE <- as.factor(data$Objective)  
data$PURPOSE <- as.factor(data$Purpose)  
data$DURATION <- as.factor(data$Duration)  
data$INV_MONITOR <- as.factor(data$Invest_Monitor) 
data$AVENUE <- as.factor(data$Avenue) 


#Gráficos de barras de variables categóricas
plot(data$FACTOR)

plot(data$GENDER)

plot(data$STOCK_MARKET)

plot(data$OBJECTIVE)

plot(data$PURPOSE)

plot(data$DURATION)

plot(data$INV_MONITOR)

plot(data$AVENUE)

Pie charts de variables categoricas, cualitativas o cuantitativas discretas

#Diagramas de sectores variables categóricas, cualitativas o cuantitativas discretas
g <- ggplot(data, aes(x=TRUE, fill=GENDER)) + geom_bar(width=1)
g + coord_polar(theta = "y")

g <- ggplot(data, aes(x=TRUE, fill=STOCK_MARKET)) + geom_bar(width=1)
g + coord_polar(theta = "y")

g <- ggplot(data, aes(x=TRUE, fill=PURPOSE)) + geom_bar(width=1)
g + coord_polar(theta = "y")

g <- ggplot(data, aes(x=TRUE, fill=DURATION)) + geom_bar(width=1)
g + coord_polar(theta = "y")

Distribucion de edades por genero

# Age distribution by gender
ggplot(data, aes(x = age, color = GENDER)) +
  geom_density(alpha = 0.5) + 
  labs(title = "Frequency of Age Range by Gender",
       x = "Age",
       y = "Density") 

Graficos de barra

# Age distribution by gender
ggplot(data, aes(x = age, color = GENDER)) +
  geom_density(alpha = 0.5) + 
  labs(title = "Frequency of Age Range by Gender",
       x = "Age",
       y = "Density") 

# Plot in a bar chart Investment purpose by gender
data %>%
  count(GENDER, PURPOSE) %>%
  ggplot(aes(x = GENDER, y = n, fill = PURPOSE)) +
  geom_bar(stat = "identity", position = "stack") +
  labs(title = "Investment purpose by gender", x = "GENERO", y = "Purpose") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Plot in a bar chart Investment Objective by age 
data %>%
  count(OBJECTIVE, age) %>%
  ggplot(aes(x = age, y = n, fill = OBJECTIVE)) +
  geom_bar(stat = "identity", position = "stack") +
  labs(title = "Investment Objective by age ", x = "Age", y = "Objective") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Plot in a bar chart Investment Objective by gender 
data %>%
  count(OBJECTIVE, GENDER) %>%
  ggplot(aes(x = GENDER, y = n, fill = OBJECTIVE)) +
  geom_bar(stat = "identity", position = "stack") +
  labs(title = "Investment Objective by gender ", x = "Gender", y = "Objective") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Plot in a bar chart Investor age by gender
data %>%
  count(age, GENDER) %>%
  ggplot(aes(x = GENDER, y = n, fill = age)) +
  geom_bar(stat = "identity", position = "stack") +
  labs(title = "Investor age by gender ", x = "Gender", y = "Age") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Plot in a bar chart Insvestment duration by gender
data %>%
  count(DURATION, GENDER) %>%
  ggplot(aes(x = GENDER, y = n, fill = DURATION)) +
  geom_bar(stat = "identity", position = "stack") +
  labs(title = "Insvestment duration by gender", x = "Gender", y = "Duration") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Plot in a bar chart Insvestment duration by age
data %>%
  count(age, DURATION) %>%
  ggplot(aes(x = DURATION, y = n, fill = age)) +
  geom_bar(stat = "identity", position = "stack") +
  labs(title = "Insvestment duration by age", x = "Age", y = "Duration") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

CONCLUSIONES

-El perfil del inversor medio es hombre entre 25 y años, con objetivo de apreciacion de capital (capital appreciation).
-El perfil de inversor mujer suele ser mas joven que el perfil hombre.
-La mayoria de los inversores prefieren invertir en oro y debentures (bonos u obligaciones).
-La duracion de la inversion suele ser de 1-3 años o 3-5 años.
-La mayoria de los inversores hacen un seguimiento mensual de la inversion.
-Hay muy pocos inversores que inviertan por un año o mas de 5 años, y los que asi lo hacen son los inversores mas jovenes con 22 y 23 años.
-De los datos analizados, solo las mujeres se han decantado por inversiones a mas de 5 años.