{
  "hash": "c2d0687da1235de32c5ae9a007c668a7",
  "result": {
    "engine": "knitr",
    "markdown": "---\ntitle: \"Quarto Assignment\"\nauthor: \"Aare Akintunde\"\ndata: \"2026-10-05\"\nformat: html\nexecute:\n  echo: true\n---\n\n# Assignment\n\n# 1) Data Import & Initial Exploration\n\nThe Dataset: telco-customer-churn.csv was used for this assignment. It requires the loading of the dataset and initial exploration of the data. The dataset contains information about customers of a telecommunications company, including their demographics, services subscribed to, and whether they have churned (i.e., stopped using the service).\n\n# call library\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# if (!require(pacman)) { install.packages(\"pacman\") }\n\npacman::p_load(tidyverse, bulkreadr, janitor, readxl, writexl)\n```\n:::\n\n\n# importing dataset and labelled as telco_data\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_data <- read_csv(\"data/telco-customer-churn.csv\")\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nRows: 7043 Columns: 21\n── Column specification ────────────────────────────────────────────────────────\nDelimiter: \",\"\nchr (17): customerID, gender, Partner, Dependents, PhoneService, MultipleLin...\ndbl  (4): SeniorCitizen, tenure, MonthlyCharges, TotalCharges\n\nℹ Use `spec()` to retrieve the full column specification for this data.\nℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.\n```\n\n\n:::\n:::\n\n\n## Exploring the dataset\n\n\n::: {.cell}\n\n```{.r .cell-code}\nhead(telco_data)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 6 × 21\n  customerID gender SeniorCitizen Partner Dependents tenure PhoneService\n  <chr>      <chr>          <dbl> <chr>   <chr>       <dbl> <chr>       \n1 7590-VHVEG Female             0 Yes     No              1 No          \n2 5575-GNVDE Male               0 No      No             34 Yes         \n3 3668-QPYBK Male               0 No      No              2 Yes         \n4 7795-CFOCW Male               0 No      No             45 No          \n5 9237-HQITU Female             0 No      No              2 Yes         \n6 9305-CDSKC Female             0 No      No              8 Yes         \n# ℹ 14 more variables: MultipleLines <chr>, InternetService <chr>,\n#   OnlineSecurity <chr>, OnlineBackup <chr>, DeviceProtection <chr>,\n#   TechSupport <chr>, StreamingTV <chr>, StreamingMovies <chr>,\n#   Contract <chr>, PaperlessBilling <chr>, PaymentMethod <chr>,\n#   MonthlyCharges <dbl>, TotalCharges <dbl>, Churn <chr>\n```\n\n\n:::\n\n```{.r .cell-code}\nglimpse(telco_data) \n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nRows: 7,043\nColumns: 21\n$ customerID       <chr> \"7590-VHVEG\", \"5575-GNVDE\", \"3668-QPYBK\", \"7795-CFOCW…\n$ gender           <chr> \"Female\", \"Male\", \"Male\", \"Male\", \"Female\", \"Female\",…\n$ SeniorCitizen    <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…\n$ Partner          <chr> \"Yes\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"Yes…\n$ Dependents       <chr> \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"Yes\", \"No\", \"No\"…\n$ tenure           <dbl> 1, 34, 2, 45, 2, 8, 22, 10, 28, 62, 13, 16, 58, 49, 2…\n$ PhoneService     <chr> \"No\", \"Yes\", \"Yes\", \"No\", \"Yes\", \"Yes\", \"Yes\", \"No\", …\n$ MultipleLines    <chr> \"No phone service\", \"No\", \"No\", \"No phone service\", \"…\n$ InternetService  <chr> \"DSL\", \"DSL\", \"DSL\", \"DSL\", \"Fiber optic\", \"Fiber opt…\n$ OnlineSecurity   <chr> \"No\", \"Yes\", \"Yes\", \"Yes\", \"No\", \"No\", \"No\", \"Yes\", \"…\n$ OnlineBackup     <chr> \"Yes\", \"No\", \"Yes\", \"No\", \"No\", \"No\", \"Yes\", \"No\", \"N…\n$ DeviceProtection <chr> \"No\", \"Yes\", \"No\", \"Yes\", \"No\", \"Yes\", \"No\", \"No\", \"Y…\n$ TechSupport      <chr> \"No\", \"No\", \"No\", \"Yes\", \"No\", \"No\", \"No\", \"No\", \"Yes…\n$ StreamingTV      <chr> \"No\", \"No\", \"No\", \"No\", \"No\", \"Yes\", \"Yes\", \"No\", \"Ye…\n$ StreamingMovies  <chr> \"No\", \"No\", \"No\", \"No\", \"No\", \"Yes\", \"No\", \"No\", \"Yes…\n$ Contract         <chr> \"Month-to-month\", \"One year\", \"Month-to-month\", \"One …\n$ PaperlessBilling <chr> \"Yes\", \"No\", \"Yes\", \"No\", \"Yes\", \"Yes\", \"Yes\", \"No\", …\n$ PaymentMethod    <chr> \"Electronic check\", \"Mailed check\", \"Mailed check\", \"…\n$ MonthlyCharges   <dbl> 29.85, 56.95, 53.85, 42.30, 70.70, 99.65, 89.10, 29.7…\n$ TotalCharges     <dbl> 29.85, 1889.50, 108.15, 1840.75, 151.65, 820.50, 1949…\n$ Churn            <chr> \"No\", \"No\", \"Yes\", \"No\", \"Yes\", \"Yes\", \"No\", \"No\", \"Y…\n```\n\n\n:::\n\n```{.r .cell-code}\nsummary(telco_data)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n     customerID         gender     SeniorCitizen         Partner    \n Length   :7043   Length   :7043   Min.   :0.0000   Length   :7043  \n N.unique :7043   N.unique :   2   1st Qu.:0.0000   N.unique :   2  \n N.blank  :   0   N.blank  :   0   Median :0.0000   N.blank  :   0  \n Min.nchar:  10   Min.nchar:   4   Mean   :0.1621   Min.nchar:   2  \n Max.nchar:  10   Max.nchar:   6   3rd Qu.:0.0000   Max.nchar:   3  \n                                   Max.   :1.0000                   \n                                                                    \n     Dependents       tenure         PhoneService    MultipleLines \n Length   :7043   Min.   : 0.00   Length   :7043   Length   :7043  \n N.unique :   2   1st Qu.: 9.00   N.unique :   2   N.unique :   3  \n N.blank  :   0   Median :29.00   N.blank  :   0   N.blank  :   0  \n Min.nchar:   2   Mean   :32.37   Min.nchar:   2   Min.nchar:   2  \n Max.nchar:   3   3rd Qu.:55.00   Max.nchar:   3   Max.nchar:  16  \n                  Max.   :72.00                                    \n                                                                   \n  InternetService   OnlineSecurity    OnlineBackup   DeviceProtection\n Length   :7043   Length   :7043   Length   :7043   Length   :7043   \n N.unique :   3   N.unique :   3   N.unique :   3   N.unique :   3   \n N.blank  :   0   N.blank  :   0   N.blank  :   0   N.blank  :   0   \n Min.nchar:   2   Min.nchar:   2   Min.nchar:   2   Min.nchar:   2   \n Max.nchar:  11   Max.nchar:  19   Max.nchar:  19   Max.nchar:  19   \n                                                                     \n                                                                     \n    TechSupport      StreamingTV    StreamingMovies      Contract   \n Length   :7043   Length   :7043   Length   :7043   Length   :7043  \n N.unique :   3   N.unique :   3   N.unique :   3   N.unique :   3  \n N.blank  :   0   N.blank  :   0   N.blank  :   0   N.blank  :   0  \n Min.nchar:   2   Min.nchar:   2   Min.nchar:   2   Min.nchar:   8  \n Max.nchar:  19   Max.nchar:  19   Max.nchar:  19   Max.nchar:  14  \n                                                                    \n                                                                    \n  PaperlessBilling   PaymentMethod  MonthlyCharges    TotalCharges   \n Length   :7043    Length   :7043   Min.   : 18.25   Min.   :  18.8  \n N.unique :   2    N.unique :   4   1st Qu.: 35.50   1st Qu.: 401.4  \n N.blank  :   0    N.blank  :   0   Median : 70.35   Median :1397.5  \n Min.nchar:   2    Min.nchar:  12   Mean   : 64.76   Mean   :2283.3  \n Max.nchar:   3    Max.nchar:  25   3rd Qu.: 89.85   3rd Qu.:3794.7  \n                                    Max.   :118.75   Max.   :8684.8  \n                                                     NAs    :11      \n       Churn     \n Length   :7043  \n N.unique :   2  \n N.blank  :   0  \n Min.nchar:   2  \n Max.nchar:   3  \n                 \n                 \n```\n\n\n:::\n\n```{.r .cell-code}\ninspect_na(telco_data)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 21 × 3\n   col_name          cnt  pcnt\n   <chr>           <int> <dbl>\n 1 TotalCharges       11 0.156\n 2 customerID          0 0    \n 3 gender              0 0    \n 4 SeniorCitizen       0 0    \n 5 Partner             0 0    \n 6 Dependents          0 0    \n 7 tenure              0 0    \n 8 PhoneService        0 0    \n 9 MultipleLines       0 0    \n10 InternetService     0 0    \n# ℹ 11 more rows\n```\n\n\n:::\n:::\n\n\n# 2) Data Transformation\n\nRecode the churn column into a binary variable where \"Yes\" = 1, and \"No\" = 0\n\nRecode the SeniorCitizen variable into a more descriptive format (e.g. \"Yes\" → \"Senior\", \"No\" → \"non-Senior\")\n\nCreate a new column ServiceCount that sums the indicators (1/0) for multiple services (e.g. PhoneService, OnlineSecurity, etc.)\n\nthese are the multiple services; PhoneService, MultipleLines, OnlineSecurity, OnlineBackup, DeviceProtection, TechSupport, StreamingTV, StreamingMovies\n\nrecode churn (\"Yes\" = 1, and \"No\" = 0) & recode SeniorCitizen (1 = \"Senior\", 0 = \"non-senior\")\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# telco_data |> mutate(Churn= if_else(Churn==\"Yes\", 1, 0))\n# telco_data |> mutate(SeniorCitizen = if_else(SeniorCitizen == 1, \"Senior\", \"non-senior\")) |> View()\n```\n:::\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_data_1 <- telco_data |>\n  mutate(\n    Churn = if_else(Churn == \"Yes\", 1, 0),\n    SeniorCitizen = if_else(SeniorCitizen == 1, \"Senior\", \"non-senior\")\n  )\nnames(telco_data_1)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n [1] \"customerID\"       \"gender\"           \"SeniorCitizen\"    \"Partner\"         \n [5] \"Dependents\"       \"tenure\"           \"PhoneService\"     \"MultipleLines\"   \n [9] \"InternetService\"  \"OnlineSecurity\"   \"OnlineBackup\"     \"DeviceProtection\"\n[13] \"TechSupport\"      \"StreamingTV\"      \"StreamingMovies\"  \"Contract\"        \n[17] \"PaperlessBilling\" \"PaymentMethod\"    \"MonthlyCharges\"   \"TotalCharges\"    \n[21] \"Churn\"           \n```\n\n\n:::\n:::\n\n\nconverting Yes/No to 1/0 for the multiple services\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_data_2 <- telco_data_1 |> \n  mutate(\n    PhoneService = if_else(PhoneService==\"Yes\", 1, 0), \n    OnlineSecurity = if_else(OnlineSecurity==\"Yes\", 1, 0), \n    OnlineBackup = if_else(OnlineBackup == \"Yes\", 1, 0), \n    DeviceProtection = if_else(DeviceProtection== \"Yes\", 1, 0), \n    TechSupport = if_else(TechSupport== \"Yes\", 1, 0), \n    StreamingTV = if_else(StreamingTV== \"Yes\", 1, 0), \n    StreamingMovies = if_else(StreamingMovies== \"Yes\", 1, 0)\n  )\n```\n:::\n\n\ncreate a new column ServiceCount\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_data_clean <- telco_data_2 |> \n  mutate(ServiceCount = PhoneService + OnlineSecurity +  OnlineBackup + DeviceProtection + TechSupport + StreamingTV + StreamingMovies) \n\nglimpse(telco_data_clean)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nRows: 7,043\nColumns: 22\n$ customerID       <chr> \"7590-VHVEG\", \"5575-GNVDE\", \"3668-QPYBK\", \"7795-CFOCW…\n$ gender           <chr> \"Female\", \"Male\", \"Male\", \"Male\", \"Female\", \"Female\",…\n$ SeniorCitizen    <chr> \"non-senior\", \"non-senior\", \"non-senior\", \"non-senior…\n$ Partner          <chr> \"Yes\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"Yes…\n$ Dependents       <chr> \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"Yes\", \"No\", \"No\"…\n$ tenure           <dbl> 1, 34, 2, 45, 2, 8, 22, 10, 28, 62, 13, 16, 58, 49, 2…\n$ PhoneService     <dbl> 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…\n$ MultipleLines    <chr> \"No phone service\", \"No\", \"No\", \"No phone service\", \"…\n$ InternetService  <chr> \"DSL\", \"DSL\", \"DSL\", \"DSL\", \"Fiber optic\", \"Fiber opt…\n$ OnlineSecurity   <dbl> 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1,…\n$ OnlineBackup     <dbl> 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0,…\n$ DeviceProtection <dbl> 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1,…\n$ TechSupport      <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0,…\n$ StreamingTV      <dbl> 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1,…\n$ StreamingMovies  <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1,…\n$ Contract         <chr> \"Month-to-month\", \"One year\", \"Month-to-month\", \"One …\n$ PaperlessBilling <chr> \"Yes\", \"No\", \"Yes\", \"No\", \"Yes\", \"Yes\", \"Yes\", \"No\", …\n$ PaymentMethod    <chr> \"Electronic check\", \"Mailed check\", \"Mailed check\", \"…\n$ MonthlyCharges   <dbl> 29.85, 56.95, 53.85, 42.30, 70.70, 99.65, 89.10, 29.7…\n$ TotalCharges     <dbl> 29.85, 1889.50, 108.15, 1840.75, 151.65, 820.50, 1949…\n$ Churn            <dbl> 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,…\n$ ServiceCount     <dbl> 1, 3, 3, 3, 1, 4, 3, 1, 5, 3, 2, 1, 4, 5, 6, 7, 1, 5,…\n```\n\n\n:::\n\n```{.r .cell-code}\nsummary(telco_data_clean)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n     customerID         gender       SeniorCitizen       Partner    \n Length   :7043   Length   :7043   Length   :7043   Length   :7043  \n N.unique :7043   N.unique :   2   N.unique :   2   N.unique :   2  \n N.blank  :   0   N.blank  :   0   N.blank  :   0   N.blank  :   0  \n Min.nchar:  10   Min.nchar:   4   Min.nchar:   6   Min.nchar:   2  \n Max.nchar:  10   Max.nchar:   6   Max.nchar:  10   Max.nchar:   3  \n                                                                    \n                                                                    \n     Dependents       tenure       PhoneService      MultipleLines \n Length   :7043   Min.   : 0.00   Min.   :0.0000   Length   :7043  \n N.unique :   2   1st Qu.: 9.00   1st Qu.:1.0000   N.unique :   3  \n N.blank  :   0   Median :29.00   Median :1.0000   N.blank  :   0  \n Min.nchar:   2   Mean   :32.37   Mean   :0.9032   Min.nchar:   2  \n Max.nchar:   3   3rd Qu.:55.00   3rd Qu.:1.0000   Max.nchar:  16  \n                  Max.   :72.00   Max.   :1.0000                   \n                                                                   \n  InternetService OnlineSecurity    OnlineBackup    DeviceProtection\n Length   :7043   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  \n N.unique :   3   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  \n N.blank  :   0   Median :0.0000   Median :0.0000   Median :0.0000  \n Min.nchar:   2   Mean   :0.2867   Mean   :0.3449   Mean   :0.3439  \n Max.nchar:  11   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  \n                  Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  \n                                                                    \n  TechSupport      StreamingTV     StreamingMovies       Contract   \n Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Length   :7043  \n 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   N.unique :   3  \n Median :0.0000   Median :0.0000   Median :0.0000   N.blank  :   0  \n Mean   :0.2902   Mean   :0.3844   Mean   :0.3879   Min.nchar:   8  \n 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   Max.nchar:  14  \n Max.   :1.0000   Max.   :1.0000   Max.   :1.0000                   \n                                                                    \n  PaperlessBilling   PaymentMethod  MonthlyCharges    TotalCharges   \n Length   :7043    Length   :7043   Min.   : 18.25   Min.   :  18.8  \n N.unique :   2    N.unique :   4   1st Qu.: 35.50   1st Qu.: 401.4  \n N.blank  :   0    N.blank  :   0   Median : 70.35   Median :1397.5  \n Min.nchar:   2    Min.nchar:  12   Mean   : 64.76   Mean   :2283.3  \n Max.nchar:   3    Max.nchar:  25   3rd Qu.: 89.85   3rd Qu.:3794.7  \n                                    Max.   :118.75   Max.   :8684.8  \n                                                     NAs    :11      \n     Churn         ServiceCount  \n Min.   :0.0000   Min.   :0.000  \n 1st Qu.:0.0000   1st Qu.:1.000  \n Median :0.0000   Median :3.000  \n Mean   :0.2654   Mean   :2.941  \n 3rd Qu.:1.0000   3rd Qu.:4.000  \n Max.   :1.0000   Max.   :7.000  \n                                 \n```\n\n\n:::\n:::\n\n\n# GBG Version\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_data_2. <- \n  telco_data_1 |> \n   mutate(\n     ServiceCount = \n       (PhoneService == \"Yes\") +\n       (OnlineSecurity == \"Yes\") +\n       (OnlineBackup == \"Yes\") +\n       (DeviceProtection == \"Yes\") +\n       (TechSupport == \"Yes\") +\n       (StreamingTV == \"Yes\") +\n       (StreamingMovies == \"Yes\"\n        )\n   )\ntelco_data_2.\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 7,043 × 22\n   customerID gender SeniorCitizen Partner Dependents tenure PhoneService\n   <chr>      <chr>  <chr>         <chr>   <chr>       <dbl> <chr>       \n 1 7590-VHVEG Female non-senior    Yes     No              1 No          \n 2 5575-GNVDE Male   non-senior    No      No             34 Yes         \n 3 3668-QPYBK Male   non-senior    No      No              2 Yes         \n 4 7795-CFOCW Male   non-senior    No      No             45 No          \n 5 9237-HQITU Female non-senior    No      No              2 Yes         \n 6 9305-CDSKC Female non-senior    No      No              8 Yes         \n 7 1452-KIOVK Male   non-senior    No      Yes            22 Yes         \n 8 6713-OKOMC Female non-senior    No      No             10 No          \n 9 7892-POOKP Female non-senior    Yes     No             28 Yes         \n10 6388-TABGU Male   non-senior    No      Yes            62 Yes         \n# ℹ 7,033 more rows\n# ℹ 15 more variables: MultipleLines <chr>, InternetService <chr>,\n#   OnlineSecurity <chr>, OnlineBackup <chr>, DeviceProtection <chr>,\n#   TechSupport <chr>, StreamingTV <chr>, StreamingMovies <chr>,\n#   Contract <chr>, PaperlessBilling <chr>, PaymentMethod <chr>,\n#   MonthlyCharges <dbl>, TotalCharges <dbl>, Churn <dbl>, ServiceCount <int>\n```\n\n\n:::\n:::\n\n\n# 3) Grouping & Summarisation\n\nUse group_by() and summarise() to calculate the churn rate for key segments (e.g. by Contract, InternetService)\n\nchurn rate by contract\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_by_contract <- telco_data_clean |>\n  group_by(Contract) |>\n  summarise(\n    churn = sum(Churn, na.rm = TRUE),\n    churn_rate = mean(Churn) * 100\n  )\ntelco_by_contract\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 3 × 3\n  Contract       churn churn_rate\n  <chr>          <dbl>      <dbl>\n1 Month-to-month  1655      42.7 \n2 One year         166      11.3 \n3 Two year          48       2.83\n```\n\n\n:::\n:::\n\n\nchurn rate by Internet Service\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_by_inter <- telco_data_clean |>\n  group_by(InternetService) |>\n  summarise(\n    churn = sum(Churn),\n    churn_rate = mean(Churn) * 100\n  )\n```\n:::\n\n\nchurn rate by both contract and Internet Service\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntelco_by_contract_internet <- telco_data_clean |> group_by(Contract, InternetService) |> \n  summarise(churn = sum(Churn, na.rm = TRUE), \n            churn_rate = mean(Churn)*100)\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\n`summarise()` has regrouped the output.\nℹ Summaries were computed grouped by Contract and InternetService.\nℹ Output is grouped by Contract.\nℹ Use `summarise(.groups = \"drop_last\")` to silence this message.\nℹ Use `summarise(.by = c(Contract, InternetService))` for per-operation\n  grouping (`?dplyr::dplyr_by`) instead.\n```\n\n\n:::\n\n```{.r .cell-code}\ntelco_by_contract_internet\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 9 × 4\n# Groups:   Contract [3]\n  Contract       InternetService churn churn_rate\n  <chr>          <chr>           <dbl>      <dbl>\n1 Month-to-month DSL               394     32.2  \n2 Month-to-month Fiber optic      1162     54.6  \n3 Month-to-month No                 99     18.9  \n4 One year       DSL                53      9.30 \n5 One year       Fiber optic       104     19.3  \n6 One year       No                  9      2.47 \n7 Two year       DSL                12      1.91 \n8 Two year       Fiber optic        31      7.23 \n9 Two year       No                  5      0.784\n```\n\n\n:::\n:::\n\n\nCalculate the overall churn rate\n\n\n::: {.cell}\n\n```{.r .cell-code}\noverall_churn <- telco_data_clean |> \n  summarise(total_churn = sum(Churn), \n            churn_rate = mean(Churn)*100)\noverall_churn\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 1 × 2\n  total_churn churn_rate\n        <dbl>      <dbl>\n1        1869       26.5\n```\n\n\n:::\n:::\n\n\nchurn rate for each Contract type\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncontract_churn <- telco_data_clean |> \n  group_by(Contract) |> \n  summarise(count = n(), \n            churn = sum(Churn), \n            churn_rate = mean(Churn)*100)\ncontract_churn\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 3 × 4\n  Contract       count churn churn_rate\n  <chr>          <int> <dbl>      <dbl>\n1 Month-to-month  3875  1655      42.7 \n2 One year        1473   166      11.3 \n3 Two year        1695    48       2.83\n```\n\n\n:::\n:::\n\n\nSummary statistics for internetservices (count, Average monthly charges, Average tenure)\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsummary_internet <- telco_data_clean |> group_by(InternetService) |> \n  summarise( ave_monthly_charges = mean(MonthlyCharges, \n                                        na.rm = TRUE),\n             ave_tenure = mean(tenure, na.rm = TRUE))\nsummary_internet\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 3 × 3\n  InternetService ave_monthly_charges ave_tenure\n  <chr>                         <dbl>      <dbl>\n1 DSL                            58.1       32.8\n2 Fiber optic                    91.5       32.9\n3 No                             21.1       30.5\n```\n\n\n:::\n:::\n\n\nUse across() to summarise monthly charges for both genders in one concise step\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# by use of summarise(.by)\ngender_summary <- telco_data_clean |>\n  summarise(\n    across(\n      MonthlyCharges,\n      list(\n        Mean = ~ mean(.x, na.rm = TRUE),\n        Median = ~ median(.x, na.rm = TRUE),\n        Minimum = ~ min(.x, na.rm = TRUE),\n        Maximum = ~ max(.x, na.rm = TRUE)\n      )\n    ),\n    .by = gender\n  )\ngender_summary\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 2 × 5\n  gender MonthlyCharges_Mean MonthlyCharges_Median MonthlyCharges_Minimum\n  <chr>                <dbl>                 <dbl>                  <dbl>\n1 Female                65.2                  70.6                   18.4\n2 Male                  64.3                  70.1                   18.2\n# ℹ 1 more variable: MonthlyCharges_Maximum <dbl>\n```\n\n\n:::\n\n```{.r .cell-code}\n# by use of group_by() and summarise() combo\ntelco_data_clean |>\n  group_by(gender) |>\n  summarise(\n    mean_charges = mean(MonthlyCharges, na.rm = TRUE),\n    median_charges = median(MonthlyCharges, na.rm = TRUE),\n    min_charges = min(MonthlyCharges, na.rm = TRUE),\n    max_charges = max(MonthlyCharges, na.rm = TRUE)\n  )\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 2 × 5\n  gender mean_charges median_charges min_charges max_charges\n  <chr>         <dbl>          <dbl>       <dbl>       <dbl>\n1 Female         65.2           70.6        18.4        119.\n2 Male           64.3           70.1        18.2        118.\n```\n\n\n:::\n\n```{.r .cell-code}\ntelco_data_clean\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 7,043 × 22\n   customerID gender SeniorCitizen Partner Dependents tenure PhoneService\n   <chr>      <chr>  <chr>         <chr>   <chr>       <dbl>        <dbl>\n 1 7590-VHVEG Female non-senior    Yes     No              1            0\n 2 5575-GNVDE Male   non-senior    No      No             34            1\n 3 3668-QPYBK Male   non-senior    No      No              2            1\n 4 7795-CFOCW Male   non-senior    No      No             45            0\n 5 9237-HQITU Female non-senior    No      No              2            1\n 6 9305-CDSKC Female non-senior    No      No              8            1\n 7 1452-KIOVK Male   non-senior    No      Yes            22            1\n 8 6713-OKOMC Female non-senior    No      No             10            0\n 9 7892-POOKP Female non-senior    Yes     No             28            1\n10 6388-TABGU Male   non-senior    No      Yes            62            1\n# ℹ 7,033 more rows\n# ℹ 15 more variables: MultipleLines <chr>, InternetService <chr>,\n#   OnlineSecurity <dbl>, OnlineBackup <dbl>, DeviceProtection <dbl>,\n#   TechSupport <dbl>, StreamingTV <dbl>, StreamingMovies <dbl>,\n#   Contract <chr>, PaperlessBilling <chr>, PaymentMethod <chr>,\n#   MonthlyCharges <dbl>, TotalCharges <dbl>, Churn <dbl>, ServiceCount <dbl>\n```\n\n\n:::\n:::\n\n\n# 4. Data Visualization\n\nExploratory visualizations\n\nDistribution of customer tenure\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# tenure-histogram\n\n\nggplot(telco_data_clean, aes(x = tenure)) +\n  geom_histogram(binwidth = 5, boundary = 0, color = \"white\") +\n  labs(x = \"Tenure (months)\", y = \"Number of customers\") +\n  theme_minimal()\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-16-1.png){width=672}\n:::\n:::\n\n\nThe histogram reveals how customers are distributed across the customer lifecycle and helps identify concentrations of very new and long-standing customers.\n\nChurned versus non-churned customers\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# churn-bar\n\n\nggplot(telco_data_clean, aes(x = Churn, fill = Churn)) +\n  geom_bar(show.legend = FALSE) +\n  labs(x = \"Churn status\", y = \"Number of customers\") +\n  theme_minimal()\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nWarning: The following aesthetics were dropped during statistical transformation: fill.\nℹ This can happen when ggplot fails to infer the correct grouping structure in\n  the data.\nℹ Did you forget to specify a `group` aesthetic or to convert a numerical\n  variable into a factor?\n```\n\n\n:::\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-17-1.png){width=672}\n:::\n:::\n\n\nThe bar chart makes the class balance visible and provides context for interpreting the overall churn rate.\n\n# Discussion Points\n\nData transformation with `dplyr` converts raw records into analysis-ready variables and summaries. In this report, `mutate()` creates the binary churn indicator, descriptive senior-citizen label, average charge metric, and service count. `group_by()` and `summarise()` produce churn rates and segment-level statistics, while `across()` applies the same statistical functions efficiently to multiple variables. The result is shorter, more readable, reproducible code and a dataset that can move naturally from exploratory analysis into predictive modelling.",
    "supporting": [
      "index_files"
    ],
    "filters": [
      "rmarkdown/pagebreak.lua"
    ],
    "includes": {},
    "engineDependencies": {},
    "preserve": {},
    "postProcess": true
  }
}