mle

Power Law Fit of cut-off distribution with the poweRlaw package

最后都变了- 提交于 2019-12-12 18:36:20
问题 I am currently trying to find a way to calculate a power-law fit for a cut-off distribution with MLE. The distribution looks as follows: As you can see, I was able to fit the whole distribution (Power-law fit) and also the lower bound (exp-fit) separately. What I am failing to figure out, is how to fit the upper bound of the distribution (f.e. 8 < x < 100). Is there any way to do this with the poweRlaw package or any other R package? What I am hoping for is something looking like this (note:

More MLE troubles

假装没事ソ 提交于 2019-12-11 03:31:17
问题 I am in a student research position and am new to R. I have asked a question similar (posted here:MLE Issues). I have resolved the initial problem but i have encountered more problems with this function. I am still using this function for trying to estimate theta[i], where each of the other variables is currently known. Below is my code: maxParam <- function(theta) { logl <- sum(for (i in 1:length(doses)) { sum( for (j in 1:LITTERS.M) { sum( for (k in 0:(litterResponses[i,j]-1)) { sum(log10

MLE error in R: initial value in 'vmmin' is not finite

老子叫甜甜 提交于 2019-12-09 02:36:57
问题 Suppose I have 2 data.frame objects: df1 <- data.frame(x = 1:100) df1$y <- 20 + 0.3 * df1$x + rnorm(100) df2 <- data.frame(x = 1:200000) df2$y <- 20 + 0.3 * df2$x + rnorm(200000) I want to do MLE. With df1 everything is ok: LL1 <- function(a, b, mu, sigma) { R = dnorm(df1$y - a- b * df1$x, mu, sigma) -sum(log(R)) } library(stats4) mle1 <- mle(LL1, start = list(a = 20, b = 0.3, sigma=0.5), fixed = list(mu = 0)) > mle1 Call: mle(minuslogl = LL1, start = list(a = 20, b = 0.3, sigma = 0.5), fixed

hand-rolled R code for Poisson MLE

我怕爱的太早我们不能终老 提交于 2019-12-08 04:46:24
问题 I'm attempting to write my own function to understand how the Poisson distribution behaves within a Maximum Likelihood Estimation framework (as it applies to GLM). I'm familiar with R's handy glm function, but wanted to try and hand-roll some code to understand what's going on: n <- 10000 # sample size b0 <- 1.0 # intercept b1 <- 0.2 # coefficient x <- runif(n=n, min=0, max=1.5) # generate covariate values lp <- b0+b1*x # linear predictor lambda <- exp(lp) # compute lamda y <- rpois(n=n,

hand-rolled R code for Poisson MLE

那年仲夏 提交于 2019-12-07 07:25:36
I'm attempting to write my own function to understand how the Poisson distribution behaves within a Maximum Likelihood Estimation framework (as it applies to GLM). I'm familiar with R's handy glm function, but wanted to try and hand-roll some code to understand what's going on: n <- 10000 # sample size b0 <- 1.0 # intercept b1 <- 0.2 # coefficient x <- runif(n=n, min=0, max=1.5) # generate covariate values lp <- b0+b1*x # linear predictor lambda <- exp(lp) # compute lamda y <- rpois(n=n, lambda=lambda) # generate y-values dta <- data.frame(y=y, x=x) # generate dataset negloglike <- function

Error with custom density function definition for mle2 formula call

℡╲_俬逩灬. 提交于 2019-12-06 11:31:39
I want to define my own density function to be used in the formula call to mle2 from R 's bbmle package. The parameters of the model are estimated but I cannot apply functions like residuals or predict on the returned mle2 object. This is an example in which I define a function for a simple Poisson model. library(bbmle) set.seed(1) hpoisson <- rpois(1000, 10) myf <- function(x, lambda, log = FALSE) { pmf <- (lambda^x)*exp(-lambda)/factorial(x) if (log) log(pmf) else pmf } myfit <- mle2(hpoisson ~ myf(lambda), start = list(lambda=9), data=data.frame(hpoisson)) residuals(myfit) In myfit , the

Reproduce a prior density plot in R

℡╲_俬逩灬. 提交于 2019-12-05 06:22:58
问题 I am still getting used to converting formulas to code in R. I am trying to work through the empirical Bayes chapter (chapter 6) in Computer Age Statistical Inference. I would like to produce plot 6.4, but in order to do so I need to find the marginal distribution of a function of the data. To obtain the the data and plot it I did the following. nodes <- read.table("https://web.stanford.edu/~hastie/CASI_files/DATA/nodes.txt", header = T) nodes %>% ggplot(aes(x=x/n))+ geom_histogram(bins = 30)

Does Quasi Separation matter in R binomial GLM?

自古美人都是妖i 提交于 2019-12-02 17:16:32
问题 I am learning how the quasi-separation affects R binomial GLM. And I start to think that it does not matter in some circumstance . In my understanding, we say that the data has quasi separation when some linear combination of factor levels can completely identify failure/non-failure. So I created an artificial dataset with a quasi separation in R as: fail <- c(100,100,100,100) nofail <- c(100,100,0,100) x1 <- c(1,0,1,0) x2 <- c(0,0,1,1) data <- data.frame(fail,nofail,x1,x2) rownames(data) <-

Does Quasi Separation matter in R binomial GLM?

坚强是说给别人听的谎言 提交于 2019-12-02 11:35:33
I am learning how the quasi-separation affects R binomial GLM. And I start to think that it does not matter in some circumstance . In my understanding, we say that the data has quasi separation when some linear combination of factor levels can completely identify failure/non-failure. So I created an artificial dataset with a quasi separation in R as: fail <- c(100,100,100,100) nofail <- c(100,100,0,100) x1 <- c(1,0,1,0) x2 <- c(0,0,1,1) data <- data.frame(fail,nofail,x1,x2) rownames(data) <- paste("obs",1:4) Then when x1=1 and x2=1 (obs 3) the data always doesn't fail. In this data, my

Error: “initial value in 'vmmin' is not finite” not in mle2() but in confint()

纵饮孤独 提交于 2019-12-02 09:57:20
问题 I know the web is plastered with questions (and answers) about the 'initial value in vmmim is not finite' error when trying to fit parameters for an mle2 object. I do not have this error when creating my mle2 object, but I DO get this error when trying to find the 95% CI for a parameter from an mle2 object. Here is a reproducible example: Here are the data: d = structure(list(SST_1YR = c(11.6, 11.7, 11.9, 12, 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9, 13, 13.1, 13.2, 13.3, 13.4, 13