View
152
Download
2
Category
Preview:
Citation preview
Estimador de Máxima Verosimilitud (Función GAMMA) MARCO ANTONIO MENDEZ PALMA
QUITO-ECUADOR 2010
Función GAMMA de máxima verosimilitud
Algoritmo Steep descent aplicado a la función de máxima verosimilitud para encontrar los estimadores optimos
Reales
Rate <- 1
Shape<- 3
Estimadores
[,1]
[1,] 1.014154 -> Rate
[2,] 2.792839 ->Shape
ANEXOS:
CODIGO FUENTE
#grafico
y<-seq(0.5,3.5,0.1)
x<-seq(0.5,3.5,0.1)
nc<-length(x)
f<-matrix(ncol=nc,nrow=nc)
datos=rgamma(40,3,1)
suma<-sum(datos)
suma1<-sum(log(datos))
for ( j in 1:nc)
{
for ( i in 1:nc)
{
f[i,j]=-40*y[j]*log(x[i])-40*log(gamma(y[j]))+(y[j]-1)*suma1-(1/x[i])*suma
}
}
persp(x, y, f, theta = 40, phi = 35, expand = 0.5, col = "lightblue", ltheta = 120, shade = 0.75, ticktype = "detailed", xlab = "X", ylab = "Y", zlab = "f(x,y)", main="FORMA CUADRATICA")
persp(x, y, f, theta = 40, phi = 35 , expand = 0.5,col = "white" , shade = 0.1, ticktype = "detailed", xlab = "X[1]" , ylab = "Y", zlab = "f(x,y)",main="Figura 2: Forma Cuadratica ")
#GRAFICA LAS CURVAS DE NIVEL DE LA FORMA CUADRATICA Y DEL GRADIENTE
require(grDevices)
image(x,y, f)
contour(x, y, f, col = "pink",nlevels=30, add = TRUE, method = "edge",vfont = c("sans serif", "plain"))
# steep_descent
datos=rgamma(40,3,1)
x1 <-c(1,1)
i_max <-5000
eps <-0.0001
suma<-sum(datos)
suma1<-sum(log(datos))
f1 <- expression(-40*y*log(x)-40*log(gamma(y))+(y-1)*suma1-(1/x)*suma)
fx=D(f1,"x")
fy=D(f1,"y")
fxx=D(fx,"x")
fxy=D(fx,"y")
fyx=D(fy,"x")
fyy=D(fy,"y")
steep_descent <- function(x,i_max,eps)
{
x=x1[1]
y=x1[2]
fx1=eval(fx)
fy1=eval(fy)
x_i<-c(x1[1],x1[2])
i<-0
r<-c(-fx1,-fy1)
delta<-t(r)%*%r
delta_o<-delta
while (i<i_max & delta > delta_o*eps^2)
{
x=x1[1]
y=x1[2]
fxx1=eval(fxx)
fxy1=eval(fxy)
fyy1=eval(fyy)
A <- rbind(c(fxx1,fxy1),c(fxy1,fyy1))
q<-A%*%r
alpha<-delta/(t(r)%*%q)
x1<-x1+alpha[1]*r
segments(x_i[1], x_i[2], x1[1], x1[2], col= 'black')
points(x_i[1], x_i[2],pch=16)
x_i<-x1
if (50%%(i+1)==0 )
{
x=x1[1]
y=x1[2]
fx1=eval(fx)
fy1=eval(fy)
r<-c(-fx1,-fy1)
}
else
r<-r-alpha[1]*q
delta<-(t(r)%*%r)
i<-i+1
}
x1
}
a<-steep_descent(x1,i_max,eps)
a
Recommended