<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>极大似然估计 on 格物堂</title><link>https://gewutang.cn/tags/%E6%9E%81%E5%A4%A7%E4%BC%BC%E7%84%B6%E4%BC%B0%E8%AE%A1/</link><description>Recent content in 极大似然估计 on 格物堂</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Tue, 13 Sep 2011 00:00:00 +0000</lastBuildDate><atom:link href="https://gewutang.cn/tags/%E6%9E%81%E5%A4%A7%E4%BC%BC%E7%84%B6%E4%BC%B0%E8%AE%A1/index.xml" rel="self" type="application/rss+xml"/><item><title>非线性模型极大似然估计方法</title><link>https://gewutang.cn/2011/09/13/max-likelyho/</link><pubDate>Tue, 13 Sep 2011 00:00:00 +0000</pubDate><guid>https://gewutang.cn/2011/09/13/max-likelyho/</guid><description>&lt;h2 id="一模型设定与概率框架"&gt;&lt;a href="#%e4%b8%80%e6%a8%a1%e5%9e%8b%e8%ae%be%e5%ae%9a%e4%b8%8e%e6%a6%82%e7%8e%87%e6%a1%86%e6%9e%b6" class="header-anchor"&gt;&lt;/a&gt;一、模型设定与概率框架&#10;&lt;/h2&gt;&lt;p&gt;设非线性生产函数形式为：&#10;$$&#10;y_i = aL_i^bK_i^c + \epsilon_i \quad (i=1,&amp;hellip;,n)&#10;$$&#10;其中误差项 &lt;code&gt;\(\epsilon_i \sim N(0,\sigma^2)\)&lt;/code&gt;，则观测值 &lt;code&gt;\(y_i\)&lt;/code&gt; 服从均值为 &lt;code&gt;\(aL_i^bK_i^c\)&lt;/code&gt;、方差为 &lt;code&gt;\(\sigma^2\)&lt;/code&gt; 的正态分布。&lt;/p&gt;&#10;&lt;h2 id="二似然函数构建"&gt;&lt;a href="#%e4%ba%8c%e4%bc%bc%e7%84%b6%e5%87%bd%e6%95%b0%e6%9e%84%e5%bb%ba" class="header-anchor"&gt;&lt;/a&gt;二、似然函数构建&#10;&lt;/h2&gt;&lt;h3 id="1-联合概率密度函数"&gt;&lt;a href="#1-%e8%81%94%e5%90%88%e6%a6%82%e7%8e%87%e5%af%86%e5%ba%a6%e5%87%bd%e6%95%b0" class="header-anchor"&gt;&lt;/a&gt;1. 联合概率密度函数&#10;&lt;/h3&gt;&lt;p&gt;$$&#10;L(a,b,c,\sigma) = \prod_{i=1}^n \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left[ -\frac{(y_i-aL_i^bK_i^c)^2}{2\sigma^2} \right]&#10;$$&lt;/p&gt;&#10;&lt;h3 id="2-负对数似然函数目标函数"&gt;&lt;a href="#2-%e8%b4%9f%e5%af%b9%e6%95%b0%e4%bc%bc%e7%84%b6%e5%87%bd%e6%95%b0%e7%9b%ae%e6%a0%87%e5%87%bd%e6%95%b0" class="header-anchor"&gt;&lt;/a&gt;2. 负对数似然函数（目标函数）&#10;&lt;/h3&gt;&lt;p&gt;$$&#10;\ell(a,b,c,\sigma) = -\ln L = \frac{n}{2}\ln(2\pi) + n\ln\sigma + \frac{1}{2\sigma^2}\sum_{i=1}^n (y_i - aL_i^bK_i^c)^2&#10;$$&lt;/p&gt;&#10;&lt;h2 id="三参数估计流程"&gt;&lt;a href="#%e4%b8%89%e5%8f%82%e6%95%b0%e4%bc%b0%e8%ae%a1%e6%b5%81%e7%a8%8b" class="header-anchor"&gt;&lt;/a&gt;三、参数估计流程&#10;&lt;/h2&gt;&lt;h3 id="1-数据处理与准备"&gt;&lt;a href="#1-%e6%95%b0%e6%8d%ae%e5%a4%84%e7%90%86%e4%b8%8e%e5%87%86%e5%a4%87" class="header-anchor"&gt;&lt;/a&gt;1. 数据处理与准备&#10;&lt;/h3&gt;&lt;pre&gt;&lt;code class="language-r"&gt;# 导入数据&#10;data &amp;lt;- data.frame(&#10; y = c(76,47,97,107,123,139,159,152,191,201,207,200),&#10; L = c(0.02,0.02,0.06,0.06,0.11,0.11,0.22,0.22,0.56,0.56,1.10,1.10),&#10; K = c(1.1,0.9,2.3,2.1,3.4,3.6,4.5,4.3,5.8,6.0,7.2,7.0)&#10;)&#10;&#10;# 定义负对数似然函数&#10;mloglik &amp;lt;- function(theta) {&#10; a &amp;lt;- theta[1]&#10; b &amp;lt;- theta[2]&#10; c &amp;lt;- theta[3]&#10; sigma &amp;lt;- theta[4]&#10; &#10; y_pred &amp;lt;- a * data$L^b * data$K^c&#10; residuals &amp;lt;- data$y - y_pred&#10; n &amp;lt;- length(data$y)&#10; &#10; # 避免\sigma 趋近于零&#10; if(sigma &amp;lt;= 0) return(1e10)&#10; &#10; (n/2)*log(2*pi) + n*log(sigma) + sum(residuals^2)/(2*sigma^2)&#10;}&#10;&#10;# 采用线性化方法获取初始值&#10;log_model &amp;lt;- lm(log(y) ~ log(L) + log(K), data = data)&#10;theta_init &amp;lt;- c(&#10; exp(coef(log_model)[1]),&#10; coef(log_model)[2],&#10; coef(log_model)[3],&#10; sd(resid(log_model))&#10;)&#10;&#10;# 优化求解&#10;fit &amp;lt;- nlm(mloglik, theta_init, hessian = TRUE)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## Warning in nlm(mloglik, theta_init, hessian = TRUE): NA/NaN replaced by maximum&#10;## positive value&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## Warning in nlm(mloglik, theta_init, hessian = TRUE): Inf replaced by maximum&#10;## positive value&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# 提取估计结果&#10;params &amp;lt;- fit$estimate&#10;names(params) &amp;lt;- c(&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;sigma&amp;quot;)&#10;params&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## a b c sigma &#10;## 55.45620820 -0.02273718 0.67704166 7.67493891&#10;&lt;/code&gt;&lt;/pre&gt;&#10;</description></item></channel></rss>