温莎日记 27

Maximum Likelihood Estimators - Matlab example

As a motivation, let us look at one Matlab example. Let us generate a random sample of size 100 from beta distribution Beta(5, 2). We will learn the definition of beta distribution later, at this point we only need to know that this is a continuous distribution on the interval [0, 1]. This can be done by typing ’X=betarnd(5,2,100,1)’. Let us fit different distributions by using a distribution fitting tool ’dfittool’. 

Fitting a random sample of size 100 from Beta(5, 2). (a) Histogram of the dataand p.d.f.s of fitted normal (solid line) and beta (dashed line) distributions; (b) Empirical’s of fitted normal and beta distributions.

Besides the graphs, the distribution fitting tool outputs the following information:

Distribution:     Normal

Log likelihood: 55.2571

Domain:          -Inf < y < Inf

Mean:              0.742119

Variance:        0.0195845

Parameter Estimate  Std. Err.

mu                   0.742119       0.0139945

sigma              0.139945       0.00997064

Estimated covariance of parameter estimates:  

                          mu                  sigma

mu             0.000195845      6.01523e-020

sigma        6.01523e-020     9.94136e-005

Distribution:     Beta

Log likelihood: 63.8445

Domain:          0 < y < 1

Mean:             0.741371

Variance:        0.0184152

Parameter     Estimate     Std. Err.

a                   6.97783     1.08827

b                   2.43424      0.378351

Estimated covariance of parameter estimates:

                          a                 b

a                 1.18433        0.370094

b                  0.370094     0.143149

The value ’Log likelihood’ indicates that the tool uses the maximum likelihood estimators to fit the distribution, which will be the topic of the next few lectures. Notice the ’Parameter estimates’ - given the data ’dfittool’ estimates the unknown parameters of the distribution and then graphs the p.d.f. or c.d.f. corresponding to these parameters.

One can ask several questions about this example:

1. How to estimate the unknown parameters of a distribution given the data from this distribution?

2. How good are these estimates, are they close to the actual ’true’ parameters?

3. Does data come from a particular type of distribution, for example, normal or beta distribution?

Wikipedia article about normal distribution gives a reference to a 1932 book ”Problems of Relative Growth” by Julian Huxley for the explanation why the sizes of full-grown animals are approximately log-normal. One short explanation is consistency between linear and volume dimensions - if linear dimensions are log-normal and volume dimensions are proportional to cube of linear dimensions then they also are log-normal. Assumption that sizes are normal would violate this consistency, since the cube of normal is not normal. We observe, however, that the fit of women’s waist with log-normal is not very accurate. Later in the class we will learn several statistical tests to decide if the data comes from a certain distribution or a family of distributions, but here is a preview of what’s to come. Chi-squared goodness-of-fit test rejects the hypothesis that the distribution of logarithms of women’s waists is normal:

[h,p,stats]=chi2gof(log_women_waist)

h = 1, p = 5.2297e-004

stats = chi2stat: 22.0027

            df: 5

           edges: [1x9 double]

           O: [21 44 67 60 28 18 12 10]

           E: [1x8 double]

and so does Lilliefor’s test (adjusted Kolmogorov-Smirnov test):

[h,p,stats]=lillietest(log_women_waist)

h = 1, p = 0, stats = 0.0841.


The same tests accept the hypotheses that other variables have log-normal distribution.

Fitting weight (upper left) and waist girth (upper right) with log-normal distribution. Lower left: fitting women’s waist with shifted Gamma and normal distributions.

As we can see, Gamma fits the data better than log-normal and much better than normal. To find the parameters of fitted Gamma distribution we use Matlab ’gamfit’ function:

param=gamfit(women_waist_shift)

param = 2.8700      4.4960.

Chi-squared goodness-of-fit test for a specific (fitted) Gamma distribution:

[h,p,stats]=chi2gof(women_waist_shift,’cdf’,@(z)gamcdf(z,param(1),param(2)))

h = 0, p = 0.9289, stats = chi2stat: 2.4763, df: 7

accepts the hypothesis that the sample has Gamma distribution \Gamma (2.87, 4.496). This test is not ’accurate’ in some sense, which will be explained later. One can also check that Gamma distribution fits well other variables - men’s waist girth, weight of men and weight of women.


Uniform distribution U[0, ϕ] on the interval [0, ϕ].

This distribution has p.d.f. f(x|\theta )=\frac{1}{\theta } , if 0 \leq  x \leq  \theta ; otherwise is 0. The likelihood function 

\varphi (\theta )=\prod_{i=1}^n f(x_i|\theta )=\frac{1}{\theta ^n} I(X_1,...,X_n\in [0,\theta ])=\frac{1}{\theta ^n} I(max(X_1,...,x_n)\leq   \theta ).

Here the indicator function I(A) equals to 1 if event A happens and 0 otherwise. What the indicator above means is that the likelihood will be equal to 0 if at least one of the factors is 0 and this will happen if at least one observation X_i will fall outside of the ’allowed’ interval [0, ϕ]. Another way to say it is that the maximum among observations will exceed ϕ, i.e.

\varphi (\theta )=0 if \theta <max(X_1,...,X_n); and \varphi (\theta )=\frac{1}{\theta ^n}  if \theta \geq max(X_1,...,X_2).

MLE for the uniform distribution

Sometimes it is not so easy to find the maximum of the likelihood function as in example above and one might have to do it numerically. Also, MLE does not always exist. The difference is that we ’excluded’ the point ϕ by setting f(\theta |\theta )=0. Then the likelihood function is

\varphi (\theta )=\prod_{i=1}^n f(X_i|\theta )=\frac{1}{\theta ^n} I(max(X_1,...,X_n)<\theta ),

and the maximum at the point \hat{\theta } =max(X_1,...,X_n) is not achieved. Of course, this is an artificial example that shows that sometimes one needs to be careful.


References:

[1] Grete Heinz, Louis J. Peterson, Roger W. Johnson, Carter J. Kerk, (2003) “Exploring Relationships in Body Dimensions“. Journal of Statistics Education, Volume 11, Number 2.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,293评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,604评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,958评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,729评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,719评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,630评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,000评论 3 397
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,665评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,909评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,646评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,726评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,400评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,986评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,959评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,996评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,481评论 2 342

推荐阅读更多精彩内容