matlab likelihood,Maximum-Likelihood-Estimation

Maximum-Likelihood-Estimation

所属分类:matlab例程

开发工具:Visual C++

文件大小:253KB

下载次数:20

上传日期:2014-04-28 22:12:31

上 传 者:雪之恋

说明:  用MATLAB编写代码,在经济和金融中法对连续时间过程实现了封闭的最大似然估计方法

(The code, written in MATLAB, implements the closed-form maximum-likelihood estimation method for continuous-time processes in economics and finance. First, the code maximizes the log-likelihood function and displays the MLE estimates, the standard error estimates (constructed from the inverse of Hessian) and the misspecification-robust standard error (i.e., the sandwich estimate). Second, it reports whether the maximization procedure converges under the default tolerance. Finally, it plots the marginal log-likelihood for each parameter in a neighborhood of the estimates. The blue curve is the likelihood function, while each red star corresponds to the estimate for the corresponding parameter. For more information about the models, please read the user s guide (link "more").)

文件列表:[举报垃圾]

Codes_Matlab.rar,260202,2014-04-28

main_script_MLE.m,2361,2014-04-28

近期下载者:

相关文件:

收藏者:

最大似然估计是一种估计模型参数的方法,通常会用到Matlab软件来进行计算。下面是一个简单的用Matlab进行最大似然估计拟合的代码示例: 假设我们要拟合一个正态分布模型,假设数据集已知,我们的目标是根据该数据集来估计正态分布的均值和标准差。 代码分为以下四个步骤: 第一步:设置模型和数据集 我们使用normpdf函数构造正态分布模型,并通过randn函数生成具有个样本的数据集: x = -5:0.1:5; % 样本空间 mu_true = -0.5; % 真实均值 s_true = 1.2; % 真实标准差 data = mu_true + s_true * randn(1,10000); % 样本大小为10000个 y = normpdf(x,mu_true,s_true); % 构造正态分布函数 subplot(1,2,1) % 绘制图形 plot(x,y) xlabel('x') ylabel('probability density') subplot(1,2,2) histogram(data,30,'Normalization','pdf') % 绘制样本数据直方图 xlabel('x') ylabel('probability density') 第二步:定义似然函数 我们使用正态分布的似然函数: function y = llh_normal(data, mu, sigma) y = -0.5 * sum(log(2*pi*sigma^2) + ((data - mu).^2)./sigma^2); end 第三步:似然函数的最大化 在Matlab中,您可以使用fminsearch函数最小化负对数似然函数以最大化似然函数。以下是拟合代码: mu_0 = -1; % 初始估计均值 s_0 = 1; % 初始标准偏差 x0 = [mu_0, s_0]; % 初始估计 % 计算最大似然估计 options = optimset('MaxIter',500,'TolX',1e-6,'TolFun',1e-6); % 设置优化选项 [xhat, fval, exitflag] = fminsearch(@(x) -llh_normal(data, x(1), x(2)), x0, options); mu_est = xhat(1); % 估计的均值 s_est = xhat(2); % 估计的标准偏差 disp(['mu_true = ', num2str(mu_true)]) disp(['s_true = ', num2str(s_true)]) disp(['mu_est = ', num2str(mu_est)]) disp(['s_est = ', num2str(s_est)]) 第四步:结果可视化 我们使用拟合的结果来绘制拟合正态分布函数和数据集的直方图。 subplot(1,2,1) y_true = normpdf(x,mu_true,s_true); % 真实正态分布函数 plot(x,y_true,'k--',x,y,'b',x,normpdf(x,mu_est,s_est),'r:','LineWidth',2) legend('true','samples','estimate') xlabel('x') ylabel('probability density') subplot(1,2,2) histogram(data,30,'Normalization','pdf') hold on plot(x,normpdf(x,mu_est,s_est),'r-','LineWidth',2) legend('samples','estimate') xlabel('x') ylabel('probability density') 以上就是用Matlab进行最大似然估计拟合的代码示例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值