search for: logl

Displaying 20 results from an estimated 59 matches for "logl".

Did you mean: log
2010 Oct 29
3
How to scan df from a specific word?
Hi R-helpers, I need to read some file with different lines (I don't know the number of lines to skip) and I would like to find a way to start reading the data.frame from the word "source". ex: djhsafk asdfhkjash shdfjkash asfhjkash #those lines contain numbers and words, I want to skip then but they have different sizes asdfhjkash asdfhjksa source tret 2 res 3 Can
2006 Oct 27
1
(no subject)
Hi, I have generated a profile likelihood for a parameter (x) and am trying to get 95% confidence limits by calculating the two points where the log likelihood (LogL) is 2 units less than the maximum LogL. I would like to do this by linear interpolation and so I have been trying to use the function approxfun which allows me to get a function to calculate LogL for any value of x within the range of x values. My data frame can be entered as follows: dat...
2005 May 31
1
Solved: linear regression example using MLE using optim()
...cients[,1], d$sigma) # Switch to log sigma as the free parameter theta.true[3] <- log(theta.true[3]) theta.ols[3] <- log(theta.ols[3]) # OLS likelihood function -- ols.lf <- function(theta, K, y, X) { beta <- theta[1:K] sigma <- exp(theta[K+1]) e <- (y - X%*%beta)/sigma logl <- sum(log(dnorm(e)/sigma)) return(logl) } # Experiment with the LF -- cat("Evaluating LogL at stupid theta : ", ols.lf(c(1,2,1), 2, y, X), "\n") cat("Evaluating LogL at true params : ", ols.lf(theta.true, 2, y, X), "\n") cat("Evaluating LogL at O...
2010 Jul 07
3
Boxplots over a Scatterplot
...t;, header=T) #specifies a dataframe foram<-data.frame(emdata) #calculates actual dimensions in mm foram$actual_l<-foram$length/foram$magnification foram$actual_w<-foram$width/foram$magnification foram$actual_h<-foram$height/foram$magnification #takes logs of all dimensions foram$logl<-log10(foram$actual_l) foram$logw<-log10(foram$actual_w) foram$logh<-log10(foram$actual_h) #Generates scatterplot plot(foram$stage, foram$logl, ylab="log max size", xlab="stage", cex=.1, xaxt="n", axes=FALSE ) axis(at=-3:1, side=2, pos=0) axis(at...
2005 Jun 29
2
MLE with optim
Hello, I tried to fit a lognormal distribution by using optim. But sadly the output seems to be incorrect. Who can tell me where the "bug" is? test = rlnorm(100,5,3) logL = function(parm, x,...) -sum(log(dlnorm(x,parm,...))) start = list(meanlog=5, sdlog=3) optim(start,logL,x=test)$par Carsten. [[alternative HTML version deleted]]
2008 Mar 04
6
vector manipulations
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080304/9de37092/attachment.pl
2007 Jun 19
1
Error handling
...e, in the simulation study the error comes up quite rarely but still it is annoying to handle it manually each time. Many thanks Peter The example: ------------ logfunc <- function (params) { vutil1 <- as.matrix(x2[,1:3]) %*% params vutil2 <- as.matrix(x2[,4:6]) %*% params logl <- 0 for (i in 1:6) { prob <- log((exp(vutil1[i])*achoices[i,1]+exp(vutil2[i])*achoices[i,2])/(exp(vutil1[i])+exp(vutil2[i]))) logl <- logl + prob } return (-logl) } x2 <- array(c(0,4,1,3,5,3,3,2,1,4,1,2,0,2,2,1,1,4,1.2233310 ,0.0000000 ,0.8155540 ,0.9320617 ,1.4272195 ,1...
2009 Jul 01
2
Difficulty in calculating MLE through NLM
Hi R-friends, Attached is the SAS XPORT file that I have imported into R using following code library(foreign) mydata<-read.xport("C:\\ctf.xpt") print(mydata) I am trying to maximize logL in order to find Maximum Likelihood Estimate (MLE) of 5 parameters (alpha1, beta1, alpha2, beta2, p) using NLM function in R as follows. # Defining Log likelihood - In the function it is noted as logL > library(stats) > loglike1<- function(x) + { + alpha1<-x[1] + beta1<-x[2] + alpha...
2008 Sep 11
0
Loop for the convergence of shape parameter
...advance, Jin [I]for 1) and 2) (working) % data set alpha<-1 verpi<-c(5^alpha,10^alpha-5^alpha,14^alpha-10^alpha,18^alpha-14^alpha) r<-c(1,0,0,1) k<-c(3,2,2,2) x<-c(0.5,0.5,1.0,1.0) % estimate lambda (lambda=beta0+beta1*x) GLM_results <- glm(r/k ~ x, family=binomial(link='cloglog'), offset=log(verpi),weights=k) beta0<-GLM_results$coefficients[[1]] beta1]<-GLM_results$coefficients[[2]] lambda1<-beta0+beta1*x[1] lambda2<-beta0+beta1*x[2] % using lambda, estimate alpha (a=alpha) through ML estimation L<-function(a){ s1_f1<-(exp(-lambda1*(0^a-0^a))-exp(...
2008 Dec 31
2
function of mixture normal with covariates
...for the likelihood attached in the document. For some reason it's not working I keep getting \this error: Error: unexpected symbol in: " +log(v_pred)) return" > } Error: unexpected '}' in "}" > > opp<-optim(c(meany0,meany1,stdy0,stdy1,dx,V,d),logl) Error in optim(c(meany0, meany1, stdy0, stdy1, dx, V, d), logl) : function cannot be evaluated at initial parameters > This is what I wrote # maximizing the log likelihood function logl<-function(param,y,x) { mu0=param[1] mu1=param[2] sdy0=param[3] sdy1=param[4] pix_pre...
2010 Jul 08
2
Using nlm or optim
Hello, I am trying to use nlm to estimate the parameters that minimize the following function: Predict<-function(M,c,z){ + v = c*M^z + return(v) + } M is a variable and c and z are parameters to be estimated. I then write the negative loglikelihood function assuming normal errors: nll<-function(M,V,c,z,s){ n<-length(Mean) logl<- -.5*n*log(2*pi) -.5*n*log(s) - (1/(2*s))*sum((V-Predict(Mean,c,z))^2) return(-logl) } When I put the Mean and Variance (variables with 136 observations) into this function, and estimates for c,z, a...
2008 Aug 12
2
Maximum likelihood estimation
...A I get 0.92 for a, and 0.73 for b. Code that I use in R is: p<-matrix(data$p) # price at time t lp<-cbind(1,data$lp) # price at time t-1 mle <- function(theta) { sigma2<-theta[1] b<- theta[-1] n<-length(p) e<-p-lp%*%b logl<- -(n/2)*log(sigma2)-((t(e)%*%e)/(2*sigma2)) return(-logl) } out <- optim(c(0,0,0),mle, method = "L-BFGS-B", lower = c(0, -Inf, -Inf), upper = c(Inf, Inf, Inf)) The "result" I get is: " Error in optim(c(0, 0, 0), mle, method = "L-BFGS-B", lowe...
2008 Sep 19
2
Error: function cannot be evaluated at initial parameters
I have an error for a simple optimization problem. Is there anyone knowing about this error? lambda1=-9 lambda2=-6 L<-function(a){ s2i2f<-(exp(-lambda1*(250^a)-lambda2*(275^a-250^a)) -exp(-lambda1*(250^a)-lambda2*(300^a-250^a))) logl<-log(s2i2f) return(-logl)} optim(1,L) Error in optim(1, L) : function cannot be evaluated at initial parameters Thank you in advance -- View this message in context: http://www.nabble.com/Error%3A--function-cannot-be-evaluated-at-initial-parameters-tp19565286p19565286.html Sent from the R hel...
2011 Dec 01
1
Estimation of AR(1) Model with Markov Switching
...ep(0,100) y[1] <- y1 for(i in 2:100) { if(state[i]==0) { y[i] <- 2 + 0.5 * y[i-1] + rnorm(1) } else { y[i] <- 0.5 + 0.9 * y[i-1] + rnorm(1) } } # convert into time series object y <- ts(y, start = 1, freq = 1) # construct negative conditional likelihood function neg.logl <- function(theta, data) { # construct parameters beta_s0 <- theta[1:2] beta_s1 <- theta[3:4] sigma2 <- exp(theta[5]) gamma0 <- theta[6] gamma1 <- theta[7] # construct probabilities #probit specification p_s0_s0 <- pnorm(gamma_s0) p_s0_s1 <- pnorm(gamma_s1) p...
2005 May 30
1
Trying to write a linear regression using MLE and optim()
I wrote this: # Setup problem x <- runif(100) y <- 2 + 3*x + rnorm(100) X <- cbind(1, x) # True OLS -- lm(y ~ x) # OLS likelihood function -- ols.lf <- function(theta, K, y, X) { beta <- theta[1:K] sigma <- exp(theta[K+1]) e <- (y - X%*%beta)/sigma logl <- sum(log(dnorm(e))) return(logl) } optim(c(2,3,0), ols.lf, gr=NULL, method="BFGS", lower=-Inf, upper=Inf, control=list(trace=2, fnscale=-1), # Now for the "..." stuff K, y, X) I get: Error in fn(par, ...) : argument "X" is missing, wi...
2006 Mar 13
1
Formatting an anova table using latex
...anova(raw1.lmer0, raw1.lmer, raw1.lmerI), file = 'raw1.tex', rownamesTexCmd = c('baR', 'addit', 'multip'), longtable = F, dcolumn = T, booktabs = T, t able.env = F, colheads = NULL, colnamesTexCmd = c ('', 'df', 'aic', 'bic', 'logl', 'chisq', 'chisqdf', 'prchisq')) I get: % latex.default(anova(raw1.lmer0, raw1.lmer, raw1.lmerI), file = "raw1.tex", rownamesTexCmd = c("baR", "addit", "multip"), longtable = F, dcolumn = T, booktabs = T, table.env...
2010 Mar 26
1
Problems if optimization
...pars,y){ beta1<-pars[1] beta2<-pars[2] beta3<-pars[3] beta4<-pars[4] beta5<-pars[5] alfa1<-pars[6] Fsp<-log(1/(1+exp(beta1*y[,10]+beta2*y[,3]+beta3*y[,3]+beta4*y[,5]+beta5*y[,6]+alfa1*y[,11]))) Frp<-log(1/(1+exp(beta1*y[,10]+beta2*y[,3]+beta3*y[,3]+beta4*y[,5]+beta5*y[,6]))) logl<- sum((y[,15]*Fsp)+(y[,19]*Frp)) return(-logl) } optim(c(1,1,1,1,1,1), llMix, y=Mix, method="CG") Erro em optim(c(1, 1, 1, 1, 1, 1), llMix, y = Mix, method = "CG") : Função não pode ser calculada nos parâmetros iniciais optimize(c(1,1,1,1,1,1),llMix,y=Mix, method="CG&q...
2005 Nov 18
1
Truncated observations in survreg
...;-function(x,y,alpha=0,beta=1,sigma=1,s) { sum( log((dnorm(y,mean=alpha+beta*x,sd=sigma^2)/(1-pnorm(q=s,mean=alpha+beta*x,sd=sigma^2)))) ) } ll<-function(x,y,alpha=0,beta=1,sigma=1,s) { aa<-function(z){a(z[1],z[2],alpha=alpha,beta=beta,sigma=sigma,s=s)} v<-apply(cbind(x,y),1,aa) sum(v) } logl<-function(pars) { -a(x=e$x,y=e$y,alpha=pars[1],beta=pars[2],sigma=pars[3],s=0.1) } ss<-optim(c(0,0,1),logl) print(s) print(ss) Best Regards Per Jensen [[alternative HTML version deleted]]
2009 Sep 14
1
Error: C stack usage is too close to the limit
...6,88.3,91.6,99,115) > t=3:12 > fn <- function(params, l=l, t=t) { Linf <- params[1] k <- params[2] t0 <- params[3] sigma <- params[4] lhat <- params[1]*(1-exp(-params[2]*(t-params[3]))) logL <- -sum(dnorm(log(l),log(lhat),sqrt(sigma),TRUE)) return(logL) } > resop <- optim(c(120, .1, 0, 1), fn, method="L-BFGS-B",lower=c(0.0, 0.001, 0.001,0.01) + ,upper = rep(Inf, 4), hessian=TRUE, control=list(trace=1)) Error: C stack usage is too close...
2013 Apr 01
1
Parameter Estimation in R with Sums and Lagged Variables
...ame up with this approach because I thought it would be a good idea to estimate the slope of the weights rather than estimating one parameter for each lag of X added (I intent to set n very large). Is that easily doable in R? My first try looks like this: parameters<-function(alpha,y){ logl<- for(i in 1:n){ sum((alpha[1]+alpha[2]*i)*lag(xvar,i)) } return(-logl) } optim(c(0.001,0.001),parameters,y=yvar) It is really hard to find any clear sources when it comes to optimization including lags. I would really appreciate if someone could help me out on this one! K...