Score, Hessian and Newton Raphson function of the exponential distribution in R

1

How to find the scoring vector and the Hessian array in R to apply the Newton Raphson method in the code below:

rm(list=ls())
cat("4")

#Função para simular variáveis aleatórias de uma modelo de regressão exponencial.

simula.exponencial <- function(formula, beta) {
  X <- model.matrix(formula)
  lambda <- exp(-X %*% beta)
  y <- rexp(nrow(X), lambda)
  return(data.frame(y = y, X))
}

set.seed(123)
n=10
cov <- seq(0, 5, length=n)
dados1 <- simula.exponencial(~cov, c(2,0.5))
dados1

## Função escore
escore <- function(par, formula, dados){
  mf <- model.frame(formula, dados)
  X <- model.matrix(formula, data=mf)
  esco <- ?????????
  return(drop(esco))
  }

## Hessiana

hessiano <- function(par, formula, dados){
  X <- model.matrix(formula, data=dados)
  mat <- matrix(0, nrow(X), nrow(X))
  diag(mat) <- ???????
  H <- ??????????
  return(H)
}

Thank you in advance!

    
asked by anonymous 22.04.2016 / 19:12

1 answer

0

Hi @FlavioBarros, thank you for your feedback! I was able to resolve this issue, I apologize for the delay in responding. The response script is:

## Função escore
escore <- function(par, formula, dados){
mf <- model.frame(formula, dados)
X <- model.matrix(formula, data=mf)
esco <- crossprod((n*(t(X)*par)^(-1)-model.response(mf)), t(X))
return(drop(esco))
}

## Hessiana ("naïve")
hessiano <- function(par, formula, dados){
X <- model.matrix(formula, data=dados)
mat <- matrix(0, nrow(X), nrow(X))
diag(mat) <- -exp(X%*%par)
H <- n/par^2
return(H)
}

Same finds in prof. Paulo Justiniano and others: link

    
11.09.2016 / 19:16