Believe in God

code
Author

Nikhita Purohit

Published

November 4, 2025

Do You Believe in God?

Studying Belief Patterns

EXPERIMENT OBJECTIVE: To explore whether students tend to believe in God.

1. Setting up R Packages

# SETUP CHUNK- LIBRARIES
#| label: setup
#| echo: false
#| warning: false
#| message: false

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.2
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(mosaic) # Our all-in-one package
Registered S3 method overwritten by 'mosaic':
  method                           from   
  fortify.SpatialPolygonsDataFrame ggplot2

The 'mosaic' package masks several functions from core packages in order to add 
additional features.  The original behavior of these functions should not be affected by this.

Attaching package: 'mosaic'

The following object is masked from 'package:Matrix':

    mean

The following objects are masked from 'package:dplyr':

    count, do, tally

The following object is masked from 'package:purrr':

    cross

The following object is masked from 'package:ggplot2':

    stat

The following objects are masked from 'package:stats':

    binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
    quantile, sd, t.test, var

The following objects are masked from 'package:base':

    max, mean, min, prod, range, sample, sum
library(skimr) # Looking at data

Attaching package: 'skimr'

The following object is masked from 'package:mosaic':

    n_missing
library(janitor) # Clean the data

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(naniar) # Handle missing data

Attaching package: 'naniar'

The following object is masked from 'package:skimr':

    n_complete
library(visdat) # Visualise missing data
library(tinytable) # Printing Static Tables for our data

Attaching package: 'tinytable'

The following object is masked from 'package:ggplot2':

    theme_void
library(DT) # Interactive Tables for our data
library(crosstable) # Multiple variable summaries

Attaching package: 'crosstable'

The following object is masked from 'package:purrr':

    compact
library(vcd)
Loading required package: grid

Attaching package: 'vcd'

The following object is masked from 'package:mosaic':

    mplot
library(visStatistics) # One package to test them all
### Dataset from Chihara and Hesterberg's book (Second Edition)
library(resampledata)

Attaching package: 'resampledata'

The following object is masked from 'package:datasets':

    Titanic

2. Reading and Cleaning Data

god_modified <- god <- readr::read_csv("../data/5-believe_in_god.csv")%>%
  # Clean variable names
  janitor::clean_names(case="snake")
Rows: 47 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): Name, Gender, Believe_in_God

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
god_modified
# A tibble: 47 × 3
   name      gender believe_in_god
   <chr>     <chr>  <chr>         
 1 Sanjana   Female Yes           
 2 Tathasthu Male   Yes           
 3 Vaibhav   Male   Yes           
 4 Siddharth Male   Yes           
 5 Ashik     Male   No            
 6 Kshirab   Female Yes           
 7 Niyosha   Female Yes           
 8 Charvi    Female No            
 9 Anoti     Female Yes           
10 Dhruv     Male   No            
# ℹ 37 more rows

3. Examine Data

dplyr::glimpse(god_modified)
Rows: 47
Columns: 3
$ name           <chr> "Sanjana", "Tathasthu", "Vaibhav", "Siddharth", "Ashik"…
$ gender         <chr> "Female", "Male", "Male", "Male", "Male", "Female", "Fe…
$ believe_in_god <chr> "Yes", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "No", "…
skimr::skim(god_modified)
Data summary
Name god_modified
Number of rows 47
Number of columns 3
_______________________
Column type frequency:
character 3
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
name 0 1.00 4 36 0 43 0
gender 0 1.00 4 6 0 2 0
believe_in_god 6 0.87 2 3 0 2 0
names(god_modified)
[1] "name"           "gender"         "believe_in_god"
visdat::vis_dat(god, sort_type = TRUE, palette = "default")

god_modified <- god %>% tidyr::drop_na()
god_modified
# A tibble: 41 × 3
   name      gender believe_in_god
   <chr>     <chr>  <chr>         
 1 Sanjana   Female Yes           
 2 Tathasthu Male   Yes           
 3 Vaibhav   Male   Yes           
 4 Siddharth Male   Yes           
 5 Ashik     Male   No            
 6 Kshirab   Female Yes           
 7 Niyosha   Female Yes           
 8 Charvi    Female No            
 9 Anoti     Female Yes           
10 Dhruv     Male   No            
# ℹ 31 more rows
visdat::vis_dat(god_modified, sort_type = TRUE, palette = "default")

god_modified %>%
  dplyr::count(gender, believe_in_god) %>%
  tt()
gender believe_in_god n
Female No 5
Female Yes 18
Male No 10
Male Yes 8
god_modified %>% 
  dplyr::count(gender) %>% 
  tt()
gender n
Female 23
Male 18
god_modified <- god %>%
  dplyr::mutate(across(where(is.character), as.factor))
glimpse(god_modified)
Rows: 47
Columns: 3
$ name           <fct> Sanjana, Tathasthu, Vaibhav, Siddharth, Ashik, Kshirab,…
$ gender         <fct> Female, Male, Male, Male, Male, Female, Female, Female,…
$ believe_in_god <fct> Yes, Yes, Yes, Yes, No, Yes, Yes, No, Yes, No, NA, No, …
god_modified %>%
  stats::setNames(c("Name", "Gender", "Believe_In_God"))
# A tibble: 47 × 3
   Name      Gender Believe_In_God
   <fct>     <fct>  <fct>         
 1 Sanjana   Female Yes           
 2 Tathasthu Male   Yes           
 3 Vaibhav   Male   Yes           
 4 Siddharth Male   Yes           
 5 Ashik     Male   No            
 6 Kshirab   Female Yes           
 7 Niyosha   Female Yes           
 8 Charvi    Female No            
 9 Anoti     Female Yes           
10 Dhruv     Male   No            
# ℹ 37 more rows
god_modified %>%
  DT::datatable(
    style = "default",
    caption = htmltools::tags$caption(
      style = "caption-side: top; text-align: left; color: black; font-size: 100%;", "Believe in God Dataset (Clean)"
    ),
    options = list(pageLength = 10, autoWidth = TRUE)
  ) %>%
  DT::formatStyle(
    columns = names(god_modified),
    fontFamily = "Roboto Condensed",
    fontSize = "12px",
  )

4. Data Dictionary

Qualitative Data

  1. name(fct): Name of the student
  2. gender(fct): Gender of the student
  3. believe_in_god(fct): If the student believes in God (Yes/No)

5. Graphs

1. Which gender is more likely to believe in God?

vcd::structable(data = god_modified, believe_in_god ~ gender) %>% 
  as.matrix() %>%  
  addmargins()
        believe_in_god
gender   No Yes Sum
  Female  5  18  23
  Male   10   8  18
  Sum    15  26  41
vcd::structable(believe_in_god ~ gender, data = god_modified) %>%
    vcd::mosaic(gp = shading_max,
                main = "Which gender is more likely to believe in God?")

Inferences

Females are more likely to believe in God than males. 18/23 women believe in God, whereas only 8/18 men believe in God which is surprisingly less.

2. Are there more believers than non- believers in God?

god_modified %>% 
  gf_bar(~ believe_in_god, fill = ~ believe_in_god) %>% 
  gf_labs( title = "Are there more believers than non- believers in God?",
           x = "Do You Believe in God?",
           y = "Count",
           fill = "Legend: Do you believe in God?") %>% 
  gf_refine(scale_fill_brewer(palette = "Set2", direction = -1))

Inferences

It is evident from the graph that students are more likely to believe in God. The ratio of students who believe vs do not believe in God is almost 2:1.

3. Do belief patterns in God differ between males and females?

god_modified %>% 
  gf_bar(~ believe_in_god | gender, fill = ~gender) %>% 
  gf_labs( title = "Do belief patterns in God differ between males and females?",
           x = "Do You Believe in God?",
           y = "Count",
           fill = "Legend: Gender")

Inferences

As mentioned before, Females are more likely to believe in God than males. The ratio of female believers to non- believers is almost 3.5:1, while for men it is even less than 2:1.

6. Summary of Inferences

More students believe in God than not, with roughly a 2:1 ratio overall. However, this belief is noticeably stronger among women- around 18 out of 23 females believe in God, compared to only 8 out of 18 males. Female students show a much higher believer-to-non-believer ratio (about 3.5:1), while for males it is under 2:1. Overall, belief in God is more common, and significantly more prevalent among women than men.

7. Surprising Aspects

It is surprising how so many men do not believe in God. When we look at the graph of believers vs non-believers, there are clearly more believers, but 18 of them are women and only 8 of them are men.

8. Binom test- Inference test for a single proportion

Null hypothesis: 50% of the students believe in God. Alternative hypothesis: The proportion of students who believe in God is either less than or more than 50%.

mosaic::binom.test(~ believe_in_god, data = god_modified, success = "Yes")



data:  god_modified$believe_in_god  [with success = Yes]
number of successes = 26, number of trials = 41, p-value = 0.1173
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.4693625 0.7787721
sample estimates:
probability of success 
             0.6341463 
mosaic::binom.test(~ believe_in_god, data = god_modified, success = "Yes") %>%
  broom::tidy()
# A tibble: 1 × 7
  estimate statistic p.value parameter conf.low conf.high alternative
     <dbl>     <dbl>   <dbl>     <dbl>    <dbl>     <dbl> <chr>      
1    0.634        26   0.117        41    0.469     0.779 two.sided  

From the binomial test, we can conclude that the estimate value for this sample = 0.6341463, and that based on this, the population proportion of those who find tattoos attractive is also not 0.5, since the p-value is 0.1172752. So we reject the NULL hypothesis and accept the alternative hypothesis, that the proportion is not 0.5 and more like 0.6341463