Skip to content

Instantly share code, notes, and snippets.

@Gedevan-Aleksizde
Last active October 14, 2016 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gedevan-Aleksizde/f1826ad6a7e552823c5664416e9a3914 to your computer and use it in GitHub Desktop.
Save Gedevan-Aleksizde/f1826ad6a7e552823c5664416e9a3914 to your computer and use it in GitHub Desktop.
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
Copy link
Author

return lsigma in logarithm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment