R: MaxLik estimates is just equal to the initial parameters I've set (any initial parameter)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


R: MaxLik estimates is just equal to the initial parameters I've set (any initial parameter)



I have this log-likelihood function coded and tried to maximize it using the maxLik. However, 3 out of 4 parameters I've estimated is just the same with the any initial parameter I've used.



What I know is that my actual parameters won't be sensitive on what my initial parameters are. Thus, I believe there is something wrong with my code as it does not converge to the maximum log-likelihood estimates. Any thoughts on how to fix it?


# Flexible expo-power utility function
expoUtility <- function(x, alpha, param_beta, W){
(1-exp(-alpha*(W + x)^(1-param_beta)))/alpha
}

# Calculate the probability of a single outcome in the next round
Round.Probability.Table <- cbind(Round.Probability.Table,c(1:10))
Round.Probability.Table <- Round.Probability.Table[,1:3]
names(Round.Probability.Table) <- c("Round","CasesAtEnd","Probability")

for (i in 1:9) {
Round.Probability.Table$Probability[i] <- 1/choose(Round.Probability.Table$CasesAtEnd[i],Round.Probability.Table$CasesAtEnd[i+1])
}

LL.expoUtility <- function (parameters) {

alpha <- parameters[1]
param_beta <- parameters[2]
W <- parameters[3]
sigma <- parameters[4]

LL <- foreach(i=1:nrow(data), .combine = "c", .export = ls(envir = globalenv()), .packages = c("data.table","doParallel", "maxLik", "dplyr")) %dopar% {

sv <- expoUtility(data$Bank.Offer[i], alpha = alpha, param_beta = param_beta, W = W)

cv <- combn(Set.Cases.Remaining[[i]], Round.Probability.Table[1+match(data$Round[i], Round.Probability.Table$Round),2]) %>%
apply(2,mean) %>%
sapply(FUN = predictedBankOffer, b = data$Bank.Offer.Percent[i], r = data$Round[i]) %>%
sapply(FUN = expoUtility, alpha = alpha, param_beta = param_beta, W = W)*Round.Probability.Table$Probability[data$Round[i]]
cv <- sum(cv)

delta <- combn(Set.Cases.Remaining[[i]], Round.Probability.Table[1+match(data$Round[i], Round.Probability.Table$Round), 2]) %>%
apply(2,mean) %>%
sapply(FUN = predictedBankOffer, b = data$Bank.Offer.Percent[i], r = data$Round[i]) %>%
sapply(FUN = expoUtility, alpha = alpha, param_beta = param_beta, W = W) - cv
delta <- delta^2 %>%
sum() %>%
sqrt()

if (data$Answer[i] == 0) {
z <- (cv-sv)/(delta*sigma)
} else {
z <- (sv-cv)/(delta*sigma)
}
}
LL <- sapply(LL, FUN = pnorm, mean = 0, sd = 1, log.p = TRUE)
return(LL)
}

LL.logUtility <- function (parameters) {

sigma <- parameters[1]

LL <- foreach(i=1:nrow(data), .combine = "c", .packages = c("data.table","doParallel", "maxLik", "dplyr")) %dopar% {

sv <- log(data$Bank.Offer[i])

cv <- combn(Set.Cases.Remaining[[i]], Round.Probability.Table[1+match(data$Round[i], Round.Probability.Table$Round),2]) %>%
apply(2,mean) %>%
sapply(FUN = predictedBankOffer, b = data$Bank.Offer.Percent[i], r = data$Round[i]) %>%
sapply(FUN = log)*Round.Probability.Table$Probability[data$Round[i]]
cv <- sum(cv)

delta <- combn(Set.Cases.Remaining[[i]], Round.Probability.Table[1+match(data$Round[i], Round.Probability.Table$Round), 2]) %>%
apply(2,mean) %>%
sapply(FUN = predictedBankOffer, b = data$Bank.Offer.Percent[i], r = data$Round[i]) %>%
sapply(FUN = log) - cv
delta <- delta^2 %>%
sum() %>%
sqrt()

if (data$Answer[i] == 0) {
z <- (cv-sv)/(delta*sigma)
} else {
z <- (sv-cv)/(delta*sigma)
}
}
LL <- sapply(LL, FUN = pnorm, mean = 0, sd = 1, log.p = TRUE)
return(LL)
}

## Maximise the Log likelihood function. Reported estimates equal to the Initial parameters
ptm.1 <- proc.time()
mle.1 <- maxLik(logLik = LL.expoUtility, start = c(0.1233,0.958,82370,0.1625), method = "NM", tol = 1e-20, iterlim = 3)
proc.time() - ptm.1

summary(mle.1)



P.S. I am a Windows user and a friend suggested that my codes are MAC-specific.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions