Last updated: 2023-09-06

Checks: 7 0

Knit directory: muse/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200712) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 0e79924. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    r_packages_4.3.0/

Untracked files:
    Untracked:  analysis/cell_ranger.Rmd
    Untracked:  analysis/complex_heatmap.Rmd
    Untracked:  analysis/sleuth.Rmd
    Untracked:  analysis/tss_xgboost.Rmd
    Untracked:  code/multiz100way/
    Untracked:  data/HG00702_SH089_CHSTrio.chr1.vcf.gz
    Untracked:  data/HG00702_SH089_CHSTrio.chr1.vcf.gz.tbi
    Untracked:  data/ncrna_NONCODE[v3.0].fasta.tar.gz
    Untracked:  data/ncrna_noncode_v3.fa
    Untracked:  data/netmhciipan.out.gz
    Untracked:  data/test
    Untracked:  export/davetang039sblog.WordPress.2023-06-30.xml
    Untracked:  export/output/
    Untracked:  women.json

Unstaged changes:
    Modified:   analysis/graph.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/set_notation.Rmd) and HTML (docs/set_notation.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 0e79924 Dave Tang 2023-09-06 Superset
html 5f5ccc4 Dave Tang 2023-09-06 Build site.
Rmd e02b689 Dave Tang 2023-09-06 Set notation

Introduction

The sample space, \(\Omega\), is the collection of possible outcomes of an experiment, such as a die roll:

\[ \Omega = \{1, 2, 3, 4, 5, 6\} \]

An event, say \(E\), is a subset of \(\Omega\), such as the even dice rolls:

\[ E = \{2, 4, 6\} \]

An elementary or simple event is a particular result of an experiment, such as the roll of 4 and is represented as a lowercase omega.

\[ \omega = 4 \]

A null event or the empty set is represented as:

\[ \emptyset \].

Interpretations of set operations

  1. Is an element of

\[ \omega \in E \]

implies that \(E\) occurs when \(\omega\) occurs; for example if \(\omega = 4\) occurs, then the event \(E\) (even number) occurs.

  1. Not an element of

\[ \omega \not \in E \]

implies that \(E\) does not occur when \(\omega\) occurs; for example if \(\omega = 5\), \(E\) (even numbers) does not occur.

  1. Subset

\[ E \subset F \]

implies that the occurrence of \(E\) implies the occurrence of \(F\); for example if \(E = \{2, 4, 5\}\) and \(F = \{2, 4, 5, 6\}\).

  1. Intersect

\[ E \cap F \]

implies the event that both \(E\) and \(F\) occur; for example if \(E = \{2, 4, 6\}\) (even numbers) and \(F = \{2, 3, 5\}\) (prime numbers), then \(E \cap F = 2\).

  1. Union

\[ E \cup F \]

implies the event that at least one of \(E\) or \(F\) occur; for example if \(E = \{2, 4, 6\}\) (even numbers) and \(F = \{2, 3, 5\}\) (prime numbers), then \(E \cup F = \{2, 3, 4, 5, 6\}\), which is that we get either an even number or a prime number or both.

  1. If intersect == null event

\[ E \cap F = \emptyset \]

implies that \(E\) and \(F\) are mutually exclusive, or cannot both simultaneously occur; for example if \(E = \{2, 4, 6\}\) (even numbers) and \(F = \{1, 3, 5\}\) (odd numbers).

  1. Complement

\[ E^\complement \]

is the event that \(E\) does not occur; for example if \(E\) are the even numbers then \(E^\complement\) are the odd numbers.

A superset is a set that contains all the elements of another set, as well as additional elements. For example if \(E = \{2, 4, 5\}\) and \(F = \{2, 4, 5, 6\}\), then \(F\) is a superset of \(E\). A superset is just the inverse of a subset, which you can see in the mathematical notation; \(E\) is a subset of \(F\).

\[ F \supset E \\ E \subset F \\ \]

Set theory facts

DeMorgan’s laws

\[ (A \cap B)^\complement = A^\complement \cup B^\complement\]

\[ (A \cup B)^\complement = A^\complement \cap B^\complement\]

To remember these laws, think of distributing the complements to \(A\) and \(B\) and then inverting the cap into a cup or vice versa.

\[ (A^\complement)^\complement = A \]

The complement of \(A\) complemented = \(A\).

And lastly:

\[ (A \cup B) \cap C = (A \cap C) \cup (B \cap C) \]

Probability and set notation

Consider influenza epidemics for two parent heterosexual families. Suppose that the probability is 17% that at least one of the parents has contracted the disease. The probability that the father has contracted influenza is 12% while the probability that both the mother and father have contracted the disease is 6%. What is the probability that the mother has contracted influenza?

Let \(M\) be the mother and \(F\) be the father.

Recall that the union (\(\cup\)) implies the event that at least one of \(M\) or \(F\) occurred, therefore:

\[ P(M \cup F) = 17\%. \]

The probability that the father contracted influenza is 12%:

\[ P(F) = 12\%. \]

An intersection (\(\cap\)) implies the event that both M and F occur, i.e. the probability that both the mother and father have contracted the disease:

\[ P(M \cap F) = 6\%. \]

We know that:

\[ P(M \cup F) = P(M) + P(F) - P(M \cap F).\]

It is worth noting that if the events are mutually exclusive, \(P(M \cap F) = 0\), since they both can’t occur together, but in our case the events can occur together. From the above equation, we get:

\[ 17 = P(M) + 12 - 6 \\ P(M) = 17 - 12 + 6 \\ P(M) = 11%. \]

Therefore the probability of the mother contracting the disease is 11%.

You may be more familiar with the addition rule in probability, which is:

\[ P(M\ or\ F) = P(M) + P(F) - P(M\ and\ F) \\ 17 = P(M) + 12 - 6 \\ P(M) = 17 - 12 + 6 \\ P(M) = 11 \]

Conditional probability

The probability of getting a 1 when rolling a fair die is \(\frac{1}{6}\). If we are given the extra information that the die roll was an odd number (1, 3 or 5), conditional on this new information, the probability of a 1 is now \(\frac{1}{3}\). Let’s test this example out:

Let \(B\) be an event so that \(P(B) > 0\), i.e. it’s an event that actually occurs. Then the conditional probability of an event \(A\) given that \(B\) has occurred is:

\[ P(A | B) = \frac{P(A \cap B)}{P(B)}. \]

So using the example above:

\[ B = \{1, 3, 5\}\ and\ A = \{1\} \]

Therefore:

\[ P(A | B) = \frac{P(A \cap B)}{P(B)} = \frac{P(A)}{P(B)} = \frac{\frac{1}{6}}{\frac{3}{6}} = \frac{1}{3} \]


sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.9.2 forcats_1.0.0   stringr_1.5.0   dplyr_1.1.2    
 [5] purrr_1.0.1     readr_2.1.4     tidyr_1.3.0     tibble_3.2.1   
 [9] ggplot2_3.4.2   tidyverse_2.0.0 workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] sass_0.4.6       utf8_1.2.3       generics_0.1.3   stringi_1.7.12  
 [5] hms_1.1.3        digest_0.6.31    magrittr_2.0.3   timechange_0.2.0
 [9] evaluate_0.21    grid_4.3.0       fastmap_1.1.1    rprojroot_2.0.3 
[13] jsonlite_1.8.5   processx_3.8.1   whisker_0.4.1    ps_1.7.5        
[17] promises_1.2.0.1 httr_1.4.6       fansi_1.0.4      scales_1.2.1    
[21] jquerylib_0.1.4  cli_3.6.1        rlang_1.1.1      munsell_0.5.0   
[25] withr_2.5.0      cachem_1.0.8     yaml_2.3.7       tools_4.3.0     
[29] tzdb_0.4.0       colorspace_2.1-0 httpuv_1.6.11    vctrs_0.6.2     
[33] R6_2.5.1         lifecycle_1.0.3  git2r_0.32.0     fs_1.6.2        
[37] pkgconfig_2.0.3  callr_3.7.3      pillar_1.9.0     bslib_0.5.0     
[41] later_1.3.1      gtable_0.3.3     glue_1.6.2       Rcpp_1.0.10     
[45] xfun_0.39        tidyselect_1.2.0 rstudioapi_0.14  knitr_1.43      
[49] htmltools_0.5.5  rmarkdown_2.22   compiler_4.3.0   getPass_0.2-2