[R] parameter estimation point estimation
According to the sample to estimate the overall distribution of the unknown parameters included, called parameter estimation (parametric estimation), which is an important form of statistical inference, there are usually two ways: point estimation and confidence interval.
Point estimation (point estimation)
Point estimate is a statistic used to estimate the unknown parameters
advantage: the ability to clearly tell people, "roughly how many unknown parameters"
Disadvantages: can not reflect the credibility of estimates
Moment Method
The central idea of the moment method is used to estimate the overall sample moments moments
R procedure is as follows:
x<-rbinom(100, 20, 0.7); n<-length(x)
A1<-mean(x); M2<-(n-1)/n*var(x)
source("../moment_fun.R");
source("../../Newtons.R")
p<-c(10,0.5); Newtons(moment_fun, p)
k<-A1^2/(A1-M2); k
p<-(A1-M2)/A1; p
x<-rbinom(100,20,0.7) #产生100个k=20,p=0.7的二项分布的随机数
n<-length(x)
A1<-mean(x) #计算样本均值(样本一阶原点矩)
M2<-(n-1)/n*var(x) #计算样本二阶中心距
p<-c(10,0.5)
Newtons(moment_fun,p) #给出初值,调用Newton法计算方程的根
The results are as follows
advantage Moment Method: In the case of its use, by numerical calculation, calculation often very simple
but wears moment estimation method for the other, which is often very low efficiency
Maximum likelihood method
Maximum likelihood method is a widely used parameter estimation method, the idea began Gauss error theory, has many excellent properties, which make full use of the overall information distribution function, overcomes some of the deficiencies of the moment method
uniroot () function
Roots uniroot function with equation (), find the roots of the likelihood function
x<-rcauchy(1000,1) #产生1000个参数Θ=1的随机数
f<-function(p)
+ sum((x-p)/(1+(x-p)^2)) #写出似然方程对应的函数
out<-uniroot(f,c(0,5)) #用求根函数uniroot()求似然方程在区间(0,5)内的根
out
The results are as follows:
optimize () function
Optimize software function R () (or Optimize ()) can be determined directly minima one-dimensional variable function, by which the extremum points where the log-likelihood function
loglike<-function(p) #对数似然函数
+ sum(log(1+(x-p)^2))
out<-optimize(loglike,c(0,5)) #用函数optimize()求函数loglike在区间(0,5)上的极小点
out
The results are as follows:
nlm () function
nlm function of Function minimum value can be evaluated
written to the target function in R:
obj<-function(x){
f<-c(10*(x[2]-x[1]^2), 1-x[1])
sum(f^2)
}
x0<-c(-1.2,1)
nlm(obj,x0)
The results are as follows: