similar to: optim and "the function should not" advice

Displaying 20 results from an estimated 9000 matches similar to: "optim and "the function should not" advice"

2010 Aug 10
1
[Fwd: Re: optimization subject to constraints]
-------------- next part -------------- An embedded message was scrubbed... From: Gildas Mazo <gildas.mazo at curie.fr> Subject: Re: [R] optimization subject to constraints Date: Tue, 10 Aug 2010 15:49:19 +0200 Size: 4924 URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100810/78862894/attachment.eml>
2010 Apr 28
1
function which saves an image of a dgtMatrix as png
Hi, I'm getting crazy: This does work: library(Matrix) a1<-b1<-c(1,2) c1<-rnorm(2) aDgt<-spMatrix(ncol=3,nrow=3,i=a1,j=b1,x=c1) png("myImage.png") image(aDgt) dev.off() But this doesn't !!! f<-function(x){ png("myImage.png") image(x) dev.off() } f(aDgt) My image is saved as a text file and contains nothing at all !!! Thanks in advance, Gildas Mazo
2010 Jul 22
4
SQL/R
Dear R users, I want to aggregate data in the following way: ### X <- data.frame(u = c("T1","T1","T1","T2"), v=c("a","a","b","a")) X library(sqldf) sqlOut <- sqldf("select count(distinct(v)) from X group by u") sqlOut ### Now I want to get the same result without using SQL. How can I achieve that ?
2012 Mar 22
4
Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Hello All, Want very much to learn how to plot patient drug timelines. Trouble is I need to figure out how to do this today. So not much time for me to struggle with it. Hoping someone can just help me out a bit. Below are some sample data and code that produces what I think is the beginning of a very nice graph. Need to alter the code to: 1. Get the lines for the drugs to appear on the
2010 Jun 04
2
Build Design Matrix with avoiding loops
Dear R users, I'd like to build a simple design matrix in a efficient way. I naively wrote the code below. #### n = 15 k = 3 nbPerGrp = c(5,5,5) xT <- list() for (i in 1:k){ xT[[i]] <- rep(0, k) xT[[i]][i] <- 1 } X <- matrix(nrow = n, ncol = k) #design matrix for (i in 1:nbPerGrp[1]){ X[i,] <- xT[[1]] } for (i in 1:k-1){ for (j
2012 Mar 06
2
Numerical Inversion of Cumulative Distribution Function
Dear R users, Given a user-defined cumulative distribution function F, I want to compute F^{-1}(x). How is that possible with R? Best Regards, -- Gildas Mazo PhD student MISTIS team at INRIA Grenoble, France [[alternative HTML version deleted]]
2010 Aug 09
2
optimization subject to constraints
Dear R users, I'm looking for tools to perform optimization subject to constraints, both linear and non-linear. I don't mind which algorithm may be used, my primary aim is to get something general and easy-to-use to study simples examples. Thanks for helping, Gildas
2004 Apr 21
2
Question on CAR appendix on NLS
The PDF file on the web, which is an appendix on nonlinear regression associated with the CAR book, is very nice. When I ran through the code presented there, I found something odd. The code does a certain model in 3 ways: Vanilla NLS (using numerical differentation), Analytical derivatives (where the user supplies the derivatives) and analytical derivatives (using automatic differentiation). The
2009 Nov 29
1
optim or nlminb for minimization, which to believe?
I have constructed the function mml2 (below) based on the likelihood function described in the minimal latex I have pasted below for anyone who wants to look at it. This function finds parameter estimates for a basic Rasch (IRT) model. Using the function without the gradient, using either nlminb or optim returns the correct parameter estimates and, in the case of optim, the correct standard
2005 Nov 15
1
An optim() mystery.
I have a Master's student working on a project which involves estimating parameters of a certain model via maximum likelihood, with the maximization being done via optim(). A phenomenon has occurred which I am at a loss to explain. If we use certain pairs of starting values for optim(), it simply returns those values as the ``optimal'' values, although they are definitely not
2009 Nov 18
1
bug in '...' of constrOptim (PR#14071)
Dear all, There appears to be a bug in how constrOptim handles ... arguments that are suppose to be passed to optim, according to the documentation. This means you can't get the hessian to be returned, for example (so this is a real problem, and not just a question of mistaken documentation). Looking at the code, it appears that a call to the user-defined f includes the ..., when the ...
2010 Nov 03
3
optim works on command-line but not inside a function
Dear all, I am trying to optimize a logistic function using optim, inside the following functions: #Estimating a and b from thetas and outcomes by ML IRT.estimate.abFromThetaX <- function(t, X, inits, lw=c(-Inf,-Inf), up=rep(Inf,2)){ optRes <- optim(inits, method="L-BFGS-B", fn=IRT.llZetaLambdaCorrNan, gr=IRT.gradZL, lower=lw, upper=up, t=t, X=X)
2003 Oct 29
1
constrOptim doesn´t send arguments to optim!(?)
Hi, I think that there something wrong with the 'constrOptim' max/minimization function because she doesn?t send extra arguments to 'optim' call. Fact: When I use optim in a f(x,theta)-like function, everything goes ok. But using constrOptim with the same function leads to error... Proof: Make a small change in the 'Rosenbrock Banana function' (taken from the Examples
2006 Sep 26
1
warning message in nlm
Dear R-users, I am trying to find the MLEs for a loglikelihood function (loglikcs39) and tried using both optim and nlm. fredcs39<-function(b1,b2,x){return(exp(b1+b2*x))} loglikcs39<-function(theta,len){ sum(mcs39[1:len]*fredcs39(theta[1],theta[2],c(8:(7+len))) - pcs39[1:len] * log(fredcs39(theta[1],theta[2],c(8:(7+len))))) } theta.start<-c(0.1,0.1) 1. The output from using optim is
2006 Sep 30
1
Gradient problem in nlm
Hello everyone! I am having some trouble supplying the gradient function to nlm in R for windows version 2.2.1. What follows are the R-code I use: fredcs39<-function(a1,b1,b2,x){return(a1+exp(b1+b2*x))} loglikcs39<-function(theta,len){ value<-sum(mcs39[1:len]*fredcs39(theta[1],theta[2],theta[3],c(8:(7+len))) - pcs39[1:len] * log(fredcs39(theta[1],theta[2],theta[3],c(8:(7+len)))))
2010 Mar 25
3
Absolutely No idea how to plot my Spatial Data
Hi, I have a data set of points which are represented by 3 variables x,y,z where x is the position of the point on the x-absciss and y on the y-absciss. Each of my points has a value z, which I want to be displayed as follows: the more z is high, the more the color on the map is dark. How can I achieve this ? Thanks for your help -- View this message in context:
2009 Apr 26
1
Stochastic Gradient Ascent for logistic regression
Hi. guys, I am trying to write my own Stochastic Gradient Ascent for logistic regression in R. But it seems that I am having convergence problem. Am I doing anything wrong, or just the data is off? Here is my code in R - lbw <- read.table("http://www.biostat.jhsph.edu/~ririzarr/Teaching/754/lbw.dat" , header=TRUE) attach(lbw) lbw[1:2,] low age lwt race smoke ptl ht ui ftv
2004 Apr 28
4
numericDeriv
Dear All, I am trying to solve a Generalized Method of Moments problem which necessitate the gradient of moments computation to get the standard errors of estimates. I know optim does not output the gradient, but I can use numericDeriv to get that. My question is: is this the best function to do this? Thank you Jean,
2010 Jun 02
1
Use apply only on non-missing values
I have a function that I am currently using very inefficiently. The following are needed to illustrate the problem: set.seed(12345) dat <- matrix(sample(c(0,1), 110, replace = TRUE), nrow = 11, ncol=10) mis <- sample(1:110, 5) dat[mis] <- NA theta <- rnorm(11) b_vector <- runif(10, -4,4) empty <- which(is.na(t(dat))) So, I have a matrix (dat) with some values within the matrix
2011 Feb 22
2
mle
Hi, I am looking for some help regarding the use of the mle function. I am trying to get mle for 3 parameters (theta0, theta1 and theta2) that have been defined in the the log-likelihood equation as theta0=theta[1], theta1=theta[2] and theta2=theta[3]. My R code for mle is: mle(Poisson.lik, start=list(theta=c(20,1,1), method="Nelder-Mead", fixed=list(w=w, t1=t1, t2=t2)) But I keep