Skip to content

Instantly share code, notes, and snippets.

@zimana
Created November 13, 2023 20:15
Show Gist options
  • Save zimana/6c44d73eed910ffb292305a80f4cab6c to your computer and use it in GitHub Desktop.
Save zimana/6c44d73eed910ffb292305a80f4cab6c to your computer and use it in GitHub Desktop.
Probability Distribution
# November 4th, 2023
#
# dbinom(k,n,p)
# k - value at which probability must be determined
# n - number of trials
# p - probability of success on each trial
#
# Discrete probability distribution -- Probability of a die side(x) being equal to 3 based on 20 tries
die_side3 <- dbinom(x=3, size= 20, prob=1/6)
# [1] 0.2378866
#
# Probability of die side (x) is equal to 0,1,2, or 3
diesideupto3 <- dbinom(x=0:3, size= 20, prob=1/6)
# returns a range of probability for each number
# [1] 0.02608405 0.10433621 0.19823881
# [4] 0.23788657
#
# This is probability of having more than q=3 successes in 20 Bernoulli trials, where each trial has a probability of success of 1/6. In other words, it returns the probability of having 4, 5, 6, ..., 19, or 20 successes.
die_morethan3 <- pbinom(q=3, size= 20, prob=1/6, lower.tail = F)
# 0.4334544
#
# The following is the same as 1 - pbinom(q=3, size= 20, prob=1/6, lower.tail = F)
# or 1 - [1] 0.4334544
die_lessthan3 <- sum(dbinom(x=0:3, size= 20, prob=1/6))
# [1] 0.5665456
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment