How do I simulate Bernoulli observations?

조회 수: 4 (최근 30일)
Chris Chen
Chris Chen 2021년 10월 15일
답변: Prachi Kulkarni 2021년 10월 18일
I want to simulate 1000 Bernoulli observations with p = 0.2 and compute an MLE estimate of p along with standard errors and t-statistics, what's the easiest way to do so?

답변 (1개)

Prachi Kulkarni
Prachi Kulkarni 2021년 10월 18일
Hi,
You can generate the Bernoulli observation and get the statistics as follows.
n = 1000;
p = 0.2;
data = binornd(1,p,n,1); % Generate 1000 observatiosn of Bernoulli Trials with p = 0.2
phat = mle(data,Distribution="Bernoulli"); % Maximum Likelihood Estimate of p
se = std(data)/sqrt(n); % Standard Error of Mean
[hypothesis,pvalue,ci,stats] = ttest(data); % t-statistics
For more information, see the following documentation.

카테고리

Help CenterFile Exchange에서 Conditional Mean Models에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by