Skip to content

Instantly share code, notes, and snippets.

@Gedevan-Aleksizde Gedevan-Aleksizde/mle.R
Last active Oct 14, 2016

Embed
What would you like to do?
require(stats4) # 3.3.1
nloglik_lnormal <- function(lmu, lsigma){
# df columns: b.u(pper border), b.l(ower border), n(umber of households)
return(-sum(with(temp,
n*log(plnorm(b.u, meanlog=lmu, sdlog = exp(lsigma))
- plnorm(b.l, meanlog=lmu, sdlog = exp(lsigma))
)
-log(n))
) - sum(log(1:sum(df$n)))
)
}
result.ln <- list()
for( a in df$region %>% unique()){
print(a)
temp <- filter(df, region == a) %>% select(b.u, b.l, n)
result.ln[[a]] <- mle(nloglik_lnormal, start=list(lmu=log(350), lsigma=1))
}
@Gedevan-Aleksizde

This comment has been minimized.

Copy link
Owner Author

commented Oct 14, 2016

return lsigma in logarithm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.