Discrete Random Variablrs dpqr

Stats_Quiz dpqr2

todo when would I use each one?

DistributionPMF/PDF (d*)CDF (p*)Quantile (q*)Random (r*)
Normaldnormpnormqnormrnorm
Binomialdbinompbinomqbinomrbinom
Geometricdgeompgeomqgeomrgeom
Hypergeometricdhyperphyperqhyperrhyper
Poissondpoisppoisqpoisrpois

Binom functions

Prob btwn 2 vars of a TRUE/FALSE outcome

  • p=prob of susc
  • k= # trials

p&dbinom table

  • k = goal
  • n=
  • p=
Probability you wantR expression
(lower tail)pbinom(k, n, p)
pbinom(k-1, n, p)
1 - pbinom(k-1, n, p)
1 - pbinom(k, n, p)
dbinom(k, n, p)
pbinom(m, n, p) - pbinom(k, n, p)

Q&Rbinom

nameexprr
Quantile function (inverse CDF)no. fail k s/t qbinom(k,n,p)
rbinomrandom samplerbinom(k,n,p)
qbinom(0.95, size=5, prob=0.5)#in 95% of simulations chance you’ll get 5 heads after x runs, in this case 11
dbinom(3, size=5, prob=0.5)   # P(3 tails before 5 heads)
rbinom(1, 10, 0.5)# in x=10 flips, how many heads?

qbinom: P(x failures b4 size-th success) {qbinom}

  • Returns failures
  • k% of experiments will require at most x{return} failures to reach n successes
  • k: percentile of trails (95% of trails will have following..)
  • n: Size per trial- p: Probability success, eg. x% succeeds (coin flip =0.5)

rbinom

  • n= # draws per trial
  • size = # of trials
  • probability? (coin flip = 0.5)

Other Distribution types

Hypergeometric Distribution

still confused Draw from a finite population without replacement. Eg. Draw 5, total 10red 40 blue

# {d,p,q,r}hyper(...)
dhyper(2, 3, 6, 4)#Probability of drawing 2 red when picking 4 marbles

Normal Distribution

Data = norm distro, takes in mean and sd

xnorm(mean,sd)#where sd = standard deviation
dnorm(x, mean, sd)   # PDF (density)
pnorm(q, mean, sd)   # P(X ≤ q)

Multinomial Distribution

https://chatgpt.com/s/t_68dd61327b648191860af24c2e9eabc6

dmultinom(x = c(2,4,4), prob = c(0.3,0.4,0.3))

Negative Binom

How many trials do I need to perform to get x sucesses? Used to get confidence intervals!

  • We generally have to re@param these functions in order to fit into the r function (from qn this)

Poisson distribution

To work it out we use:

  • d/p/q/rpois
  • WE DO NOT USE lower.tail=FALSE
    • Does not include the actual q range (middle valued range), in general it’s NOT what you want
    • If you want a upper tail, use 1-… (see Binom functions

https://chatgpt.com/s/t_68dd6184d2fc8191ac3895ddaed74b21

Used in measuring half-life decay. Lets take some neuclus, 4 particles /s on avg, being released out of it.

Defitions Random Vs Discrete Random Vs Continous Random

  1. Discrete Variable
    1. Random variable from a finite set (Pick random number from list)
  2. Continuous Variable
    1. Can take ANY value in defined range eg. [0,1] but any float between that range
    2. Not contable! Infinite possb
  3. Random Variable.
    1. assigns a numerical value to each outcome of a random process
    2. Always has some range

mathStackEx

Theroms (required to know!!) {Go over These Later (ask what Abt Them U Shuld know)}

todoStudy

Expected Value: (4.1,2,3)

Know: Sum of probility MUST be 1, a sum of constant must still be some constant

Rule 1:

For constant c

Rule 2

c is some constant wrt. x, hence can bring out infront of sum. But we already have a defition for this once we bring out the c, so its proved!

Rule 3

Vairence

Defined by:

We can expand inside:

Binomial Probaility Distro

Formula is like Combinations (Binomial Probability Distribution) Formally, in r this is described as:

dbinom(3, size = 10, prob = 0.5)

Probability of getting 3 h in 10 coin flips, whr e/a flip probability 0.5 heads

Bernouli (binomial) Probability Distribution Coin Flip Example: (will be on midterm!!)

Consider coin flip, H/T, then |sample_space|=2 (H/T)

Then

Lets toss the coin n times, then count # of heads:

For example

Moment Generating Functions: {Math}

Defined as

Use MGF derative formula (below MGF Therom)

We have 3 main defitions, all focus on the following:

MGF Therom: (ON EXAM!) See ex4.21/22

(Makes easier, instead of using defition of expected value, we can prove like so instead)

Lets have the MGF of

Example: MGF (end of ch 4)

q+p =1

Overbooking problem (project 1)

Stats_overbooking_quiz TODO

see here

  • Flight, n seats, y tickets,
  • Find: # tickets should sell?
  • will always be a given var

Given some

Lets start by figuring out

Which can be denoted by the following

pbinom(N~p)
  • N = no.seats (given)
  • a (not given!!!)
  • p=show probility (given)
  • (given)

Code example:

  • Suppose N=200 (seats on flight)
  • Prob showing up
  • Then: we can plot with our given function
#pbinom(N+1,x,p) - 1 + g =0
 
f <- function(x, N = 200, p = 0.95, g = 0.8){
 
  obj <- pbinom(N+1, x,p) -1 +g
  abs(obj)
}
 
xx <- seq(200,220,by = 1)#f(xx) -> outputs bunch of #s
#Then to solve the problem we just need to find the smallest value for this. We can just do 
 
f(xx)
 
plot(xx, f(xx),
     pch =21,
     bg = ifelse(xx != 215, "blue", "red"),
     xlab = "Number of Tickets sold",
     ylab = "Objective function",
     main = bquote(f(x) == pbinom(N+1,x,p) - 1 + gamma))
 
which(f(xx) == min(f(xx)))#OUT 16: what index works to give us our min? Then we find our min
xx[16]
#Hence, we should sell 215 tickets given all of the input data!

Lab 5 content

Generating a Random sample

Suppose that there is a bag of 20 marbles, 12 white (“1”) and 8 black “0”. Using the sample() function create a sample of size n=5 without replacement

sample(c(rep(0,12), rep(1,8)),size=5, replace=FALSE)
#where c is some array, rep(int,repeat_x_many_times)
#size=n=#taken
#replace: should sampling be with replacement? (do I take out what I just took out of the sample space? True: False
 
# If we wanted to do a coin flip:
sample(c("H","T"),size=10,prob=c(1/2,1/2),replace=TRUE) 
sample(c(1,0),size=10,prob=c(1/2,1/2), replace=TRUE)

Binomial Experiment

Simulate a binomial experiment n=10,p=0.7, and Y=number of successes.

a <- c(100, 200, 500,1000,10000)#iteratiomns
for(i in a){
  print(  mybin(iter=i,n=18, p=0.3)  )#binomial expirment
}

Formula to code

Pois calculation

1 - ppois(q = 3, lambda = 2)

Advanced choose

choose (10 - 1, 3-1) * 0.4 ^3 * 0.6 ^ (10-3)

Advance pbinom

pbinom(q = 8, size = 15, prob = 0.4)

Stuff on midterm

  • Bernouli
  • Testing problem??