Download presentation
Presentation is loading. Please wait.
Published byMatthew Riley Modified over 8 years ago
1
- 1 - Matlab statistics fundamentals Normal distribution % basic functions mew=100; sig=10; x=90; normpdf(x,mew,sig) 1/sig/sqrt(2*pi)*exp(-(x-mew)^2/sig^2/2) x=50:150; f=normpdf(x,mew,sig); plot(x,f) x=50:150; F=normcdf(x,mew,sig); plot(x,F) p=0.1; norminv(p,mew,sig) % 95% confidence interval [norminv(0.025,mew,sig) norminv(0.975,mew,sig)] % random sampling N=50; X=normrnd(mew,sig,N,1); dx=5; xx=50:dx:150; f=histc(X,xx)/N/dx; bar(xx+dx/2,f,'b') [mean(X) mode(X) median(X)] std(X) [prctile(X,2.5) prctile(X,97.5)] % repeat the process to find out difference. % repeat with N=5000 & dx=2 to find out difference. % compare also the results with N=50. % superpose pdf on random samples. N=5000; X=normrnd(mew,sig,N,1); dx=2; xx=50:dx:150; f=histc(X,xx)/N/dx; bar(xx+dx/2,f,'b') hold on; yy=normpdf(xx,mew,sig); plot(xx,yy,'r');
2
- 2 - Matlab statistics fundamentals Mean of normal dist. % mean of normal distribution mew=100; sig=10; n=10; mean(normrnd(mew,sig,n,1)) % repeat this to find out varying feature. % superpose random sampling of mean N=5000; X=normrnd(mew,sig,N,1); dx=2; xx=50:dx:150; f=histc(X,xx)/N/dx; bar(xx+dx/2,f,'b') Xm=mean(normrnd(mew,sig,n,N)); dx=2; xx=50:dx:150; fm=histc(Xm,xx)/N/dx; hold on; bar(xx+dx/2,fm,'g') % superpose pdf on random samples. yy=normpdf(xx,mew,sig); plot(xx,yy,'r'); yy=normpdf(xx,mew,sig/sqrt(n)); plot(xx,yy,'k'); Interval estimation % confidence interval of Xbar sign=sig/sqrt(n); [norminv(.025,mew,sign) norminv(.975,mew,sign)] [prctile(Xm,2.5) prctile(Xm,97.5)] [mew+norminv(.025)*sign mew+norminv(.975)*sign]
3
- 3 - Matlab statistics fundamentals Variance of normal dist. % variance of normal distribution mew=100; sig=10; n=10; var(normrnd(mew,sig,n,1)) % repeat this to find out varying feature. % random sampling of variance N=5000; S2=var(normrnd(mew,sig,n,N)); C=(n-1)*S2/sig^2; dc=.5; cc=0:dc:25; fc=histc(C,cc)/N/dc; bar(cc+dc/2,fc,'g') % superpose pdf on random samples. yy=chi2pdf(cc,n-1); hold on; plot(cc,yy,'r'); Interval estimation % confidence interval of variance normalized. [chi2inv(.025,n-1) chi2inv(.975,n-1)] [prctile(C,2.5) prctile(C,97.5)] % confidence interval of variance sig^2/(n-1)*[chi2inv(.025,n-1) chi2inv(.975,n-1)] [prctile(S2,2.5) prctile(S2,97.5)]
4
- 4 - Estimating mean with known variance Case of single data –Consider single scalar observation y from N with unknown mean –Likelihood of y –Conjugate prior implies that is exponential of a quadratic form. –Posterior density or Posterior mean is a weighted average of prior mean 0 and observed y with weights proportional to (inverse of variance) If 0 → ∞ then c 0 → 0, p( ) is constant over (-∞, ∞). Then we get 1 = y, 1 = . This means when we don’t have any knowledge on the prior distribution, we just estimate the distribution the same as the sample distribution.
5
- 5 - Estimating mean with known variance Case of single data –Posterior prediction Rearrange this in terms of q to obtain Ignore 1 st term which includes q. this becomes constant after integration. Then Mean is equal to the posterior mean. Variance has two components, predictive variance 2 and variance 1 2 due to posterior uncertainty in . So, or
6
- 6 - Estimating mean with known variance Case of multiple data –Independent & identically distributed (iid) observations –Posterior density Or Posterior distribution depends on y only through the sample mean y ̄. In fact, since y ̄ ~N( 2 /n), the result of single case can be applied with y ̄. Prior precision 1/ 0 2 and data precision n/ 2 play equivalent roles.
7
- 7 - Estimating mean with known variance Case of multiple data –Posterior density –If there is no prior knowledge, –Let’s derive this thoroughly. –Posterior prediction (in case of no prior)
8
- 8 - Estimating mean with known variance Practice –20 samples of normal distribution are given with mean 2.9 and stdev 0.2. –Plot posterior pdf of unknown population mean conditional on the observation using the analytical expression –Plot the distribution also using the simulation draw. –Superpose the two in one graph. –Plot cdf of the two together, and compute the max difference of the two.
9
- 9 - Estimating variance with known mean Multiple data are given. –Sample distribution where –In case of no information, the prior is –Posterior distribution This is rewritten as Remark – is identical to
10
- 10 - Estimating variance with known mean Practice –5 samples of normal distribution are given with sample variance 0.04. –Plot posterior pdf of unknown variance conditional on the observation using the analytical expression. –Plot the distribution also using the simulation draw. –Superpose the two in one graph. –Calculate the 95% credible interval, i.e., 2.5% & 97.5% percentiles of the distribution.
11
- 11 - Homework To be announced.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.