Last active
October 14, 2016 15:36
-
-
Save Gedevan-Aleksizde/f1826ad6a7e552823c5664416e9a3914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return lsigma in logarithm