【概念】
參數估計包括點估計和區間估計:
點估計——估計未知參數的值
區間估計——根據樣本構造出適當的空間,使它以一定的概率包含未知參數
【參數估計與matlab實現】
下面主要闡述正態總體的參數估計:
clear;
clc;
mu=10; %樣本均值
sigm=2; %樣本方差
m=50; %樣本數
n=1000; %計算置信區間的真實覆蓋率的模擬次數
x=normrnd(mu,sigm,m,1); %正態樣本
alpha=0.15;
[muhat,sigmahat,muci,sigmaci] = normfit(x,alpha);
%給出點估計和區間估計,其中muhat爲正態分佈的均值的點估計值,
%sigmahat爲標準差的點估計值,muci是均值的區間估計,sigmaci是標準差的區間估計,置信水平爲1-alpha。
[phat,pci] =mle(x); % 求均值與標準差的最大似然估計
接下來計算置信區間的真實覆蓋率(true coverage probability),維基上的解釋是:the coverage probability of a confidence interval is the proportion of the time that the interval contains the true value of interest。也就是說例如我們算了1000個置信區間,看一下其中有多少個包含了真實的參數值。
【計算置信區間的真實覆蓋率的函數代碼】
function [muratio,sigmratio]=true_fugailv(mu,sigm,m,n,alpha)
% input:
% mu is true mean of the sample
% sigm is true standard deviation(標準差) of the sample
% m is the number of the variable in sample
% n denotes how many times computer confidence interval
% 1-alpha denotes the confidence level,also denotes the nominal coverage probability
%output:
% muratio denotes the true coverage probability(真實覆蓋率) of the confidence
% intervals(置信區間) for mu
% sigmratio denotes the true coverage probability(真實覆蓋率) of the confidence
% intervals for sigm
muratio=0;
sigmratio=0;
for i=1:n
x=normrnd(mu,sigm,m,1);
[Mu,Sigm,muci,sigmci]=normfit(x,alpha);
if(muci(1)<=mu&&mu<=muci(2))
muratio=muratio+1;
end
if(sigmci(1)<=sigm&&sigm<=sigmci(2))
sigmratio=sigmratio+1;
end
end
muratio= muratio/n;
sigmratio=sigmratio/n;
【調用true_fugailv函數,並畫出true coverage probability與nominal coverage(置信水平)的關係圖】
n=1000; %計算置信區間的真實覆蓋率的模擬次數
for i=1:30
[muratio(i),sigmaciratio(i)]=true_fugailv(mu,sigm,m,n,alpha);
alpha=alpha-0.005;
end
plot(0.85:0.005:0.995,muratio,'r');
xlabel('nominal coverage');
ylabel('true coverage');
【關係圖】