01 foundations
play

01 Foundations Shravan Vasishth SMLP Shravan Vasishth 01 - PowerPoint PPT Presentation

01 Foundations Shravan Vasishth SMLP Shravan Vasishth 01 Foundations SMLP 1 / 29 Preview: Steps in Bayesian analysis The way we will conduct data analysis is as follows. Given data, specify a likelihood function . Specify prior distributions


  1. 01 Foundations Shravan Vasishth SMLP Shravan Vasishth 01 Foundations SMLP 1 / 29

  2. Preview: Steps in Bayesian analysis The way we will conduct data analysis is as follows. Given data, specify a likelihood function . Specify prior distributions for model parameters. Using software, derive marginal posterior distributions for parameters given likelihood function and prior density. Simulate parameters to get samples from posterior distributions of parameters using some Markov Chain Monte Carlo (MCMC) sampling algorithm . Evaluate whether model makes sense, using model convergence diagnostics, fake-data simulation, prior predictive and posterior predictive checks, and (if you want to claim a discovery) calibrating true and false discovery rates. Summarize posterior distributions of parameter samples and carry out your scientific conclusion. Shravan Vasishth 01 Foundations SMLP 2 / 29

  3. Bayes’ rule A and B are events. Conditional probability is defined as follows: P ( A | B ) = P ( A , B ) where P ( B ) > 0 (1) P ( B ) This means that P ( A , B ) = P ( A | B ) P ( B ). Since P ( B , A ) = P ( A , B ), we can write: P ( B , A ) = P ( B | A ) P ( A ) = P ( A | B ) P ( B ) = P ( A , B ) . (2) Rearranging terms: P ( B | A ) = P ( A | B ) P ( B ) (3) P ( A ) This is Bayes’ rule. Shravan Vasishth 01 Foundations SMLP 3 / 29

  4. Random variable theory A random variable X is a function X : S → R that associates to each outcome ω ∈ S exactly one number X ( ω ) = x . S X is all the x ’s (all the possible values of X, the support of X). I.e., x ∈ S X . We can also sloppily write X ∈ S X . Good example: number of coin tosses till H X : ω → x ω : H, TH, TTH,. . . (infinite) x = 0 , 1 , 2 , . . . ; x ∈ S X Shravan Vasishth 01 Foundations SMLP 4 / 29

  5. Random variable theory Every discrete (continuous) random variable X has associated with it a probability mass (distribution) function (pmf, pdf) . I.e., PMF is used for discrete distributions and PDF for continuous. (I will sometimes use lower case for pdf and sometimes upper case. Some books use pdf for both discrete and continuous distributions.) p X : S X → [0 , 1] (4) defined by p X ( x ) = P ( X ( ω ) = x ) , x ∈ S X (5) Shravan Vasishth 01 Foundations SMLP 5 / 29

  6. Random variable theory Probability density functions (continuous case) or probability mass functions (discrete case) are functions that assign probabilities or relative frequencies to all events in a sample space. The expression X ∼ f ( · ) (6) means that the random variable X has pdf/pmf g ( · ). For example, if we say that X ∼ N ( µ, σ 2 ), we are assuming that the pdf is 2 πσ 2 exp[ − ( x − µ ) 2 1 √ f ( x ) = ] (7) 2 σ 2 Shravan Vasishth 01 Foundations SMLP 6 / 29

  7. Random variable theory We also need a cumulative distribution function or cdf because, in the continuous case, P(X=some point value) is zero and we therefore need a way to talk about P(X in a specific range). cdfs serve that purpose. In the continuous case, the cdf or distribution function is defined as: ˆ X P ( X < x ) = F ( X < x ) = f ( x ) dx (8) −∞ Shravan Vasishth 01 Foundations SMLP 7 / 29

  8. Random variable theory f ( x ) = exp[ − ( x − µ ) 2 ] (9) 2 σ 2 This is the “kernel” of the normal pdf, and it doesn’t sum to 1: Normal density 1.0 0.8 0.6 density 0.4 0.2 0.0 −3 −2 −1 0 1 2 3 X Shravan Vasishth 01 Foundations SMLP 8 / 29

  9. Random variable theory Adding a normalizing constant makes the above kernel density a pdf. Normal density 1.0 0.8 0.6 density 0.4 0.2 0.0 −3 −2 −1 0 1 2 3 X Shravan Vasishth 01 Foundations SMLP 9 / 29

  10. Random variable theory Recall that a random variable X is a function X : S → R that associates to each outcome ω ∈ S exactly one number X ( ω ) = x . S X is all the x ’s (all the possible values of X, the support of X). I.e., x ∈ S X . X is a continuous random variable if there is a non-negative function f defined for all real x ∈ ( −∞ , ∞ ) having the property that for any set B of real numbers, ˆ P { X ∈ B } = f ( x ) dx (10) B Shravan Vasishth 01 Foundations SMLP 10 / 29

  11. Distributions if ( ! ('devtools' %in% installed.packages ()) ) install.packages ("devtools") devtools ::install_github ("bearloga/tinydensR") Then, run library (tinydensR) univariate_discrete_addin () or univariate_continuous_addin () Shravan Vasishth 01 Foundations SMLP 11 / 29

  12. Binomial distribution If we have x successes in n trials, given a success probability p for each trial. If x ∼ Bin ( n , p ). � � n p k (1 − p ) n − k P ( x | n , p ) = (11) k The mean is np and the variance np (1 − p ). dbinom(x, size, prob, log = FALSE) ### cdf: pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE) ### quantiles: qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE) ### pseudo-random generation of samples: rbinom(n, size, prob) Shravan Vasishth 01 Foundations SMLP 12 / 29

  13. The Poisson distribution This is a distribution associated with “rare events”, for reasons which will become clear in a moment. The events might be: traffic accidents, typing errors, or customers arriving in a bank. For psychology and linguistics, one application is in eye tracking: modeling number of fixations. Shravan Vasishth 01 Foundations SMLP 13 / 29

  14. The Poisson distribution Let λ be the average number of events in the time interval [0 , 1]. Let the random variable X count the number of events occurring in the interval. Then: f X ( x ) = P ( X = x ) = e − λ λ x x ! , x = 0 , 1 , 2 , . . . (12) Shravan Vasishth 01 Foundations SMLP 14 / 29

  15. Uniform distribution A random variable ( X ) with the continuous uniform distribution on the interval ( α, β ) has PDF � 1 β − α , α < x < β, f X ( x ) = (13) 0 , otherwise The associated R function is dunif( min = a , max = b ). We write X ∼ unif( min = a , max = b ). Due to the particularly simple form of this PDF we can also write down explicitly a formula for the CDF F X : Shravan Vasishth 01 Foundations SMLP 15 / 29

  16. Uniform distribution  0 , a < 0 ,    a − α F X ( a ) = (14) β − α , α ≤ t < β,   1 , a ≥ β.  and Var ( X ) = ( β − α ) 2 E [ X ] = β + α (15) 2 12 dunif(x, min = 0, max = 1, log = FALSE) punif(q, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE) qunif(p, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE) runif(n, min = 0, max = 1) Shravan Vasishth 01 Foundations SMLP 16 / 29

  17. Normal distribution − ( x − µ )2 1 f X ( x ) = √ 2 π e , −∞ < x < ∞ . (16) 2 σ 2 σ We write X ∼ norm( mean = µ, sd = σ ), and the associated R function is dnorm(x, mean = 0, sd = 1) . Normal density 0.4 0.3 density 0.2 0.1 0.0 −3 −2 −1 0 1 2 3 X Figure 1: Normal distribution. Shravan Vasishth 01 Foundations SMLP 17 / 29

  18. Normal distribution If X is normally distributed with parameters µ and σ 2 , then Y = aX + b is normally distributed with parameters a µ + b and a 2 σ 2 . Standard or unit normal random variable: If X is normally distributed with parameters µ and σ 2 , then Z = ( X − µ ) /σ is normally distributed with parameters 0 , 1. We conventionally write Φ( x ) for the CDF: ˆ x 1 − y 2 2 dy Φ( x ) = √ e where y = ( x − µ ) /σ (17) 2 π −∞ Shravan Vasishth 01 Foundations SMLP 18 / 29

  19. Normal distribution The standardized version of a normal random variable X is used to compute specific probabilities relating to X . dnorm(x, mean = 0, sd = 1, log = FALSE) pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE) qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE) rnorm(n, mean = 0, sd = 1) Shravan Vasishth 01 Foundations SMLP 19 / 29

  20. Beta distribution This is a generalization of the continuous uniform distribution. � B ( a , b ) x a − 1 (1 − x ) b − 1 1 if 0 < x < 1 f ( x ) = 0 otherwise where ˆ 1 x a − 1 (1 − x ) b − 1 dx B ( a , b ) = 0 Shravan Vasishth 01 Foundations SMLP 20 / 29

  21. Beta distribution We write X ∼ beta ( shape1 = α, shape2 = β ). The associated R function is =dbeta(x, shape1, shape2)=. The mean and variance are a ab E [ X ] = a + b and Var ( X ) = . (18) ( a + b ) 2 ( a + b + 1) Shravan Vasishth 01 Foundations SMLP 21 / 29

  22. t distribution A random variable X with PDF � − ( r +1) / 2 � 1 + x 2 f X ( x ) = Γ [( r + 1) / 2] √ r π Γ( r / 2) , −∞ < x < ∞ (19) r is said to have Student’s t distribution with r degrees of freedom, and we write X ∼ t( df = r ). The associated R functions are dt, pt, qt, and rt, which give the PDF, CDF, quantile function, and simulate random variates, respectively. We will just write: X ∼ t ( µ, σ, r ), where r is the degrees of freedom ( n − 1), where n is sample size. Shravan Vasishth 01 Foundations SMLP 22 / 29

  23. Jointly distributed random variables Visualizing bivariate distributions First, a visual of two uncorrelated normal RVs: Simulated bivariate normal density Z Y bivn.kde Figure 2: Visualization of two uncorrelated random variables. Shravan Vasishth 01 Foundations SMLP 23 / 29 #Biivariate normal distributions ariate normal density

  24. Bivariate normal distributions And here is an example with a negative correlation: Simulated bivariate normal density Z Y bivn.kde Figure 4: Visualization of two negatively correlated random variables. Shravan Vasishth 01 Foundations SMLP 24 / 29

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend