Re: [R] nls optimize

2010-10-19 Thread Ravi Varadhan
You can do this. dsm = c(800,600,NA,525,NA,450,400,NA,NA,NA,0) s3 = seq(0.05,1.05,0.1) plot(s3,dsm,col=blue,las=1,xlab=fraction,ylab=distance (km)) fc - function(x,a,b){a*exp(-b*x)} fm - nls(dsm~fc(s3,a,b),start=c(a=800,b=0)) co - coef(fm) curve(fc(x,a=co[1],b=co[2]),add=TRUE,col=black,lwd=1)

Re: [R] using optimize with two unknowns, e.g. to parameterize a distribution with given confidence interval

2010-10-19 Thread Ravi Varadhan
You cannot use `optimize' when there are two or more parameters to be optimized. I don’t know if other have suggested any solution to this, but here are 2 approaches: # Estimating LCL and UCL separately using `optimize'. prior.lcl - function(x, alpha, mean, var) { a - abs(plnorm(x, mean, var)

Re: [R] question on optim() fn.

2010-10-20 Thread Ravi Varadhan
Hi, You are doing the right thing by being concerned about the warning messages. The warning message of `NaN' usually arises due to illegal arithmetic operations (in the real number field) such as logarithm or square root of a negative number. This could happen during the intermediate stages of

Re: [R] question on optim() fn.

2010-10-21 Thread Ravi Varadhan
use optimx() to do this, although the results of the tests of first and second order conditions are sensitive to scaling of parameters and objective function. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division

Re: [R] how do I make a correlation matrix positive definite?

2010-10-22 Thread Ravi Varadhan
Nick Higham (2002) discusses algorithms for this. One of the algorithms discussed in the paper is implemented in the Matrix package as `nearPD' function. library(Matrix) ?nearPD Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf

Re: [R] Error message in using nlm() and optim()

2010-10-22 Thread Ravi Varadhan
You have not provided us sufficient information to help you. I would guess that the error message probably has something to do with the way your likelihood function is defined. Can you at least show us how the function is defined (just the argument list) and the optim call? Ravi. -Original

Re: [R] Help: Maximum likelihood estimation

2010-10-22 Thread Ravi Varadhan
I am not surprised that you are running into difficulties with this model estimation, since you are treating a constrained optimization problem as unconstrained one. It is not so easy to set constraints on the covariance matrix (i.e. positive definiteness). The is the beauty of the EM algorithm

Re: [R] how do I make a correlation matrix positive definite?

2010-10-22 Thread Ravi Varadhan
I responded to another question that asked the exact same question. So, I will repeat my answer here: Nick Higham (2002) discusses algorithms for this. One of the algorithms discussed in the paper is implemented in the Matrix package as `nearPD' function. library(Matrix) ?nearPD Ravi.

Re: [R] Help: Maximum likelihood estimation

2010-10-24 Thread Ravi Varadhan
Can you provide a reproducible code? Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu

Re: [R] Optimize parameters of ODE Problem which is solved numeric

2010-10-25 Thread Ravi Varadhan
Hi Michael, You do not need a numerical solver for this. This is a linear system of ODEs and it admits closed form solutions. The solution is given as: Y(t) = c_1 * v_1 * exp(k_1 * t) + ... + c_4 * v_4 * exp(k_4 * t) where k_1, ..., k_4 are the eigenvalues (can be real or complex) and v_1,

Re: [R] Setting constraints in the glm package

2010-10-26 Thread Ravi Varadhan
likelihood in terms of a. We then maximize this over `a' . We can use, for example, `optimize' to accomplish this. This is not contrived. I have encountered this situation in a project. Ravi. Ravi Varadhan, Ph.D. Assistant

Re: [R] Constrained Regression

2010-10-31 Thread Ravi Varadhan
be a bit tricky. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message

Re: [R] saddle points in optim

2010-11-07 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Jonathan Phillips 994p...@gmail.com Date: Sunday

Re: [R] saddle points in optim

2010-11-07 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Jonathan Phillips 994p...@gmail.com Date

Re: [R] question about constraint minimization

2010-11-22 Thread Ravi Varadhan
. --- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu -Original Message- From: r-help-boun...@r-project.org [mailto:r

Re: [R] how to calculate derivative

2010-11-22 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Yogesh Tiwari yogesh@googlemail.com

Re: [R] question about constraint minimization

2010-11-23 Thread Ravi Varadhan
, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu -Original Message- From: r-help-boun...@r

Re: [R] non-linear fourth-order differential equations

2010-11-29 Thread Ravi Varadhan
. --- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu -Original Message- From: r-help-boun...@r-project.org

Re: [R] Outlier statistics question

2010-11-30 Thread Ravi Varadhan
It is, perhaps, more apt to call the tests of outliers as tests of outright liars. Lies, damned lies, and tests of outliers Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology

Re: [R] [R-pkgs] New package list for analyzing list surveyexperiments

2010-07-15 Thread Ravi Varadhan
Let me quote the authority on naming convention: What's in a name? That which we call a rose by any other name would smell as sweet. Best, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine

Re: [R] Constrain density to 0 at 0?

2010-07-21 Thread Ravi Varadhan
assumes that the density has 0 gradient at the boundary (gradient defined from the right hand side). There are other (better) approaches as well. Look at a book on density estimation. Ravi. Ravi Varadhan, Ph.D. Assistant

[R] UseR! 2010 - my impressions

2010-07-23 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu __ R-help@r-project.org mailing list https://stat.ethz.ch

Re: [R] Optimization problem with nonlinear constraint

2010-07-26 Thread Ravi Varadhan
Hi Uli, I am not sure if this is the problem that you really want to solve. The answer is the solution to the equation y = x * T^(x-1), provided a solution exists. There is no optimization involved here. What is the real problem that you are trying to solve? If you want to solve a more

Re: [R] T and F (was: Optimization problem with nonlinear constraint)

2010-07-28 Thread Ravi Varadhan
! Uli Am 26.07.2010 17:44, schrieb Ravi Varadhan: Hi Uli, I am not sure if this is the problem that you really want to solve. The answer is the solution to the equation y = x * T^(x-1), provided a solution exists. There is no optimization involved here. What is the real problem that you

Re: [R] Optimization problem with nonlinear constraint

2010-07-28 Thread Ravi Varadhan
Very nice, Hans! I didn't know of the existence of Lambert W function (a.k.a Omega function) before. I didn't know that it occurs in the solution of exponential decay with delay: dy/dy = a * y(t - 1). Apparently it is more than 250 years old! Thanks, Ravi. -Original Message- From:

Re: [R] Optimization problem with nonlinear constraint

2010-07-28 Thread Ravi Varadhan
For those interested in esoteric of special functions, here is a nice reference on the Lambert W function: http://www.cs.uwaterloo.ca/research/tr/1993/03/W.pdf Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Hans W Borchers

Re: [R] newton.method

2010-07-29 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Dennis Murphy djmu...@gmail.com Date: Thursday, July

Re: [R] how to get higher derivatives with deriv

2010-07-30 Thread Ravi Varadhan
I am not as lazy as Peter (but neither am I as good as him)! So, please allow me to take a stab at completing his exercise: Deriv - function(fn, order=1) { ddf - fn body(ddf) - D(body(f),x) if (order 1) { for (i in 2:order) { body(ddf) - D(body(ddf),x) }

Re: [R] Computation of largest eigenvalue

2010-07-30 Thread Ravi Varadhan
There is the arpack() function in igraph package for computing leading eigenvalues, but I am not sure how well it can handle very large matrices. I have coded up an accelerated power method and have used it on dense matrices of order 5000. It takes around 9-10 secs for the dominant eigenvalue

Re: [R] newton.method

2010-08-02 Thread Ravi Varadhan
Try this: for( x in seq(0,2,length=10)) { z - nleqslv(x,f); print(c(z$x,z$fvec))} You'll see that it identifies 0.7347242 correctly as a root. Your function goes to zero asymptotically as x gets larger. From numerical algorithms's point of view, it is essentially 0 for x 3. Thus, you have

Re: [R] Need help on upper.tri()

2010-08-03 Thread Ravi Varadhan
(1) is not. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message

Re: [R] Stopping precision using 'optim'

2010-08-06 Thread Ravi Varadhan
Read the help file for optim(). ?optim It clearly says the following with regards to L-BFGS-B: factr controls the convergence of the L-BFGS-B method. Convergence occurs when the reduction in the objective is within this factor of the machine tolerance. Default is 1e7, that is a tolerance of

Re: [R] optimization subject to constraints

2010-08-09 Thread Ravi Varadhan
You may want to look at: http://cran.r-project.org/web/packages/alabama/index.html Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Gildas Mazo Sent: Monday, August 09, 2010 12:49 PM To: r-help@r-project.org Subject: [R]

Re: [R] optimization subject to constraints

2010-08-09 Thread Ravi Varadhan
constrOptim can only handle linear inequality constraints. It cannot handle equality (linear or nonlinear) as well as nonlinear inequality constraints. Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dwayne Blind Sent:

Re: [R] [Fwd: Re: optimization subject to constraints]

2010-08-10 Thread Ravi Varadhan
] -1.414213 $iterations [1] 10 $lambda [1] -0.7068717 $penalty [1] -6.496021e-08 $counts function gradient 100 30 Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School

Re: [R] Need help to understand integrate function

2010-08-11 Thread Ravi Varadhan
Try this: options(digits=10) integrate(f=powerLaw2, lower=0, upper=Inf, l1=1.8980185, l2=-0.0804259, c0=1, t0=259.78, rel.tol=1.e-10) 0.01089019946 with absolute error 3.7e-11 Ravi. Ravi Varadhan, Ph.D. Assistant

Re: [R] Need help to understand integrate function

2010-08-12 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: R_help Help rhelp

Re: [R] Constrained non-linear optimisation

2010-08-24 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Dennis Murphy djmu...@gmail.com

Re: [R] What does this warning message (from optim function) mean?

2010-08-25 Thread Ravi Varadhan
Hi, You did not give us any information about your likelihood function, f, nor did you provide a reproducible example. So, I cannot tell for sure whether the parameter estimates are reliable. Ravi. -Original Message- From: r-help-boun...@r-project.org

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
Hi Adrian, Your code for the secant method is correct. I just tweaked it a bit w/o the calendar time feature (assuming that the cash flows will be available on an annual basis) as follows: ANXIRR - function (cashFlow, guess, tol=1.e-04){ npv - function (cashFlow, irr) { n -

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
Another approach is to use `uniroot' to find the zero of the NPV function: npv - function (cashFlow, irr) { n - length(cashFlow) sum(cashFlow / (1 + irr)^{0: (n-1)}) } uniroot(f=npv, interval=c(0,1), cashFlow=cashFlow) However, there may be situations where there are no

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
. Having said that, I am not sure about the convergence problem that you are having without seeing the actual example. Ravi. -Original Message- From: Adrian Ng [mailto:a...@hamiltonlane.com] Sent: Wednesday, August 25, 2010 5:28 PM To: Ravi Varadhan; r-help@r-project.org Subject: RE: [R

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
] 0.4106115 $npv [1] 2.984279e-13 Ravi. -Original Message- From: Adrian Ng [mailto:a...@hamiltonlane.com] Sent: Wednesday, August 25, 2010 6:23 PM To: Ravi Varadhan Subject: RE: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR) The forum is kind of slow so I'm just re

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
) ANXIRR(CF, dates, guess=0.1) ANXIRR(CF, dates, guess=0.1) $irr [1] 0.3740656 $npv [1] 2.102695e-09 Hope this helps, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
: 0.3721850 fval: 3.483669 par: 0.3740179 fval: 0.08815743 par: 0.3740655 fval: 0.0002613245 par: 0.3740656 fval: 1.966778e-08 $par [1] 0.3740656 $value [1] 1.966778e-08 $iter [1] 8 Hope this helps, Ravi. Ravi Varadhan

Re: [R] R-help

2010-08-27 Thread Ravi Varadhan
However, The clue package has the solve_LSAP() function (as pointed out by Hans Werner) that solves the linear sum assignment problem, but it uses the Hungarian algorithm that was requested by you. The lp.assign() function in lpSolve package (as pointed out by Girish) also solves the linear sum

Re: [R] R-help

2010-08-27 Thread Ravi Varadhan
Of Ravi Varadhan Sent: Friday, August 27, 2010 10:28 AM To: 'venkatesh bandaru'; r-help@r-project.org Subject: Re: [R] R-help However, The clue package has the solve_LSAP() function (as pointed out by Hans Werner) that solves the linear sum assignment problem, but it uses the Hungarian algorithm

[R] Speeding up prediction of survival estimates when using `survifit'

2010-08-30 Thread Ravi Varadhan
faster alternatives. Thanks. Best, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu

Re: [R] question on optim

2010-09-07 Thread Ravi Varadhan
that the obj fn is correctly specified before we can start tackling other issues. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502

Re: [R] question on optim

2010-09-08 Thread Ravi Varadhan
Hi Nan, You can take a look at the optimx package on CRAN. John Nash and I wrote this package to help lay and sophisticated users alike. This package unifies various optimization algorithms in R for smooth, box-constrained optimization. It has features for checking objective function, gradient

Re: [R] optimized value worse than starting Value

2010-09-08 Thread Ravi Varadhan
Dieter Menne had already told you what the problem is. You have 2 local minima. One is a global minimum. Depending on your starting interval, the optimizer can converge to one of the two local minima. If you want to be reasonably sure that you always find the global minimum, you either have to

Re: [R] optimized value worse than starting Value

2010-09-08 Thread Ravi Varadhan
Numerical optimisations are best done using as many methods as possible See the optimx package: http://cran.r-project.org/web/packages/optimx/index.html Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Barry Rowlingson Sent:

Re: [R] question on optim

2010-09-08 Thread Ravi Varadhan
...@infolink.com.br] Sent: Wednesday, September 08, 2010 4:26 PM To: Ravi Varadhan Cc: 'Hey Sky'; 'Ben Bolker'; r-h...@stat.math.ethz.ch Subject: Re: [R] question on optim Dear R-list members, I am using R 2.11.1 on Windows XP. When I try to install package optimx through the GUI menu Packages / Install

Re: [R] optimized value worse than starting Value

2010-09-09 Thread Ravi Varadhan
Yes, Barry, we are aware of this issue. It is caused by printing to console from FORTRAN in one of the optimization codes, ucminf. If we set trace=FALSE in optimx, this problem goes away. Ravi. Ravi Varadhan, Ph.D

Re: [R] nonlinear programming package

2010-09-11 Thread Ravi Varadhan
, the `constrOptim' function in the base distribution can handle only linear inequality constraints. All of these packages are available on CRAN. Hope this helps, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division

Re: [R] Can I monitor the iterative/convergence process while using Optim or MaxLik?

2010-09-14 Thread Ravi Varadhan
, however, be used in `optim' when analytic gradient is not available (or for derivative free methods, e.g. Nelder-Mead). Hope this helps, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine

Re: [R] Can I monitor the iterative/convergence process while using Optim or MaxLik?

2010-09-14 Thread Ravi Varadhan
(-1.2, 1), fr, tfr - trackFn(grr)) #with(environment(tfr), matplot(X, VALUE, type=l)) with(environment(tfr), plot(X, type=l)) What is wrong here? Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine

Re: [R] Can I monitor the iterative/convergence process whileusing Optim or MaxLik?

2010-09-14 Thread Ravi Varadhan
Yes, of course! The Nelder-Mead is derivative-free. Thanks, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email

Re: [R] relative risk regression with survey data

2010-09-15 Thread Ravi Varadhan
Dear Thomas, You said, the log-binomial model is very non-robust when the fitted values get close to 1, and there is some controversy over the best approach. Could you please point me to a paper that discusses the issues? I have written some code to do maximum likelihood estimation for relative,

Re: [R] finding complex roots in R

2010-09-16 Thread Ravi Varadhan
Hi Toros, It is actually quite easy to do this with existing real-root finders. If you want to solve for F(z) = 0, where z = x + iy, you simultaneously solve for the zeros of the real and imaginary part of F. Here are a couple of examples using the package BB: fn1 - function(x, a){ z - x[1]

Re: [R] finding complex roots in R

2010-09-16 Thread Ravi Varadhan
would suggest that you use the `multiStart' function in BB to explore this in your problem. Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ravi Varadhan Sent: Thursday, September 16, 2010 3:52 PM To: 'Toros Caglar'; r-help@r

Re: [R] R Founding

2010-09-16 Thread Ravi Varadhan
Enjoyed it very much! -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tal Galili Sent: Thursday, September 16, 2010 5:31 PM To: jaropis Cc: r-h...@stat.math.ethz.ch; lig...@statistik.tu-dortmund.de; da...@revolutionanalytics.com

Re: [R] Nonlinear programming problem

2010-09-17 Thread Ravi Varadhan
Hi, You have not provided a reproducible example, so I can only make an educated guess. This is likely a numerical problem with trying to solve a linear system of equations in the Lagrange-Newton method (sequential quadratic programming or SQP) for solving nonlinearly programming problems. I am

Re: [R] How to find STRESS criteria in MDS when there are negative eigenvalues....

2010-09-17 Thread Ravi Varadhan
Perhaps, the smacof package on CRAN might be useful to you. Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Na.Ebrahimi Sent: Friday, September 17, 2010 11:08 AM To: r-help@r-project.org Subject: [R] How to find STRESS

Re: [R] Is there a bisection method in R?

2010-09-17 Thread Ravi Varadhan
Here is something simple (does not have any checks for bad input), yet should be adequate: bisect - function(fn, lower, upper, tol=1.e-07, ...) { f.lo - fn(lower, ...) f.hi - fn(upper, ...) feval - 2 if (f.lo * f.hi 0) stop(Root is not bracketed in the specified interval \n) chg - upper -

Re: [R] one step just of cliff-- zero hessian matrix in optim, with reproducable code and data

2010-09-18 Thread Ravi Varadhan
parameters, but only 50 independent data points (I presume these are 50 time-series). In short, there is nothing wrong with optimization algorithms, but there is something not right with your model. Ravi. Ravi Varadhan, Ph.D

Re: [R] one step just of cliff-- zero hessian matrix in optim, with reproducable code and data

2010-09-19 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Hey Sky heyskywal...@yahoo.com Date: Saturday, September 18, 2010 8:23

Re: [R] Is there a bisection method in R?

2010-09-20 Thread Ravi Varadhan
! Best, Ravi. From: Gregory Gentlemen [mailto:gregory_gentle...@yahoo.ca] Sent: Monday, September 20, 2010 12:52 PM To: peter dalgaard Cc: Ravi Varadhan; r-help@r-project.org Subject: Re: [R] Is there a bisection method in R? Fair enough. I didn't intend to offend anyone. Please accept my

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread Ravi Varadhan
There is nothing mysterious. You need to increase the accuracy of quadrature by decreasing the error tolerance: # I scaled your function to a proper Gaussian density shiftedGauss - function(x0=500){ integrate(function(x) 1/sqrt(2*pi * 100^2) * exp(-(x-x0)^2/(2*100^2)), 0, Inf,

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread Ravi Varadhan
rel.tol of 1.e-08 (roughly, sqrt(machine epsilon)) in my computations, and I also increase subdivisions to 500. Ravi. From: baptiste Auguié [mailto:baptiste.aug...@googlemail.com] Sent: Tuesday, September 21, 2010 9:58 AM To: Ravi Varadhan Cc: 'baptiste auguie'; 'r-help' Subject: Re: [R] puzzle

Re: [R] Trouble with Optimization in Alabama Package

2010-09-21 Thread Ravi Varadhan
I will take a look and get back to you. Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erik Kimbrough Sent: Tuesday, September 21, 2010 11:01 AM To: R-help@r-project.org Subject: [R] Trouble with Optimization in Alabama

Re: [R] Can ucminf be installed in 64 bit R and one more question?

2010-09-21 Thread Ravi Varadhan
I don’t understand your question about the hessian. Did you try hessian() function in numDeriv on the result from optim directly rather than using ucminf? Also, what do you mean by `failed'? What error message did you get? Ravi. -Original Message- From: r-help-boun...@r-project.org

Re: [R] eigen and svd

2010-09-22 Thread Ravi Varadhan
It does for real-symmetric and complex Hermitian matrices, i.e. the $u and $v from svd() are the same as $vectors from eigen() for Hermitian matrices. There might be differences in signs, but that does not matter. Of course the singular values and eigenvalues are identical too. Ravi.

Re: [R] constrained optimization -which package?

2010-09-28 Thread Ravi Varadhan
No. That would not work for equality constraints. This is quadratic programming problem. Check out `quadprog' or any other quad programming packages in R. If you have more general, nonlinearly constrained optimization you can use any one of the 3 following packages: 1. `spg' function in BB

Re: [R] constrained optimization -which package?

2010-09-28 Thread Ravi Varadhan
QP algorithm than to use a general-purpose nonlinear optimization algorithm. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410

Re: [R] nlminb and optim

2010-09-29 Thread Ravi Varadhan
Can you send your code and data as separate files so we can get it into R easily? Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410

Re: [R] R crashes when loading rgl package before minqa package

2010-09-30 Thread Ravi Varadhan
of function evaluations: 78 Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original

Re: [R] R crashes when loading rgl package before minqa package

2010-09-30 Thread Ravi Varadhan
this helps, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message

Re: [R] R crashes when loading rgl package before minqa package

2010-09-30 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Gaspard Lequeux gaspard.lequ

Re: [R] how to avoid NaN in optim()

2010-09-30 Thread Ravi Varadhan
Change the `else NA' to `else Inf' in your loglik function and then run the following: library(BB) p0 - runif(2) spg(p0, lik (176,182 , 60 ,17) , lower=0, upper=1) This will give you correct results. Ravi. Ravi

Re: [R] how to avoid NaN in optim()

2010-09-30 Thread Ravi Varadhan
I forgot to mention: You actually got correct results with using optim and `CG'. The warning messages were just telling you that there were some log(negative number) operations during the iterative process. Ravi. Ravi

Re: [R] how to avoid NaN in optim()

2010-09-30 Thread Ravi Varadhan
You also need the constrain that par[1] + par[2] 1 in order to avoid NaNs. You can do this using the `projectLinear' argument in `spg'. library(BB) ?spg Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division

Re: [R] how to avoid NaN in optim()

2010-09-30 Thread Ravi Varadhan
. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Ravi Varadhan rvarad...@jhmi.edu Date: Thursday, September 30, 2010

Re: [R] Place constrictions on parameters when using Optim and MaxLik

2010-09-30 Thread Ravi Varadhan
There are several options to implement box constraints including nlminb, BB, minqa, Rcgmin, Rvmmin. See the optimx package which integrates all of these. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric

Re: [R] how to avoid NaN in optim()

2010-10-01 Thread Ravi Varadhan
)) spg(p0, lik ( 176,182,60,17) , project=projectLinear, projectArgs=list(A=Amat, b=b, meq=0)) Hope this helps, Ravi. -Original Message- From: Ravi Varadhan [mailto:rvarad...@jhmi.edu] Sent: Thursday, September 30, 2010 3:09 PM To: Ravi Varadhan Cc: arindam fadikar; r-help@r-project.org

Re: [R] maximum likelihood problem

2010-10-01 Thread Ravi Varadhan
Do you want to do a nonlinear least-squares estimation (which is MLE if the errors are Gaussian)? If so, you have to define a function that takes the parameter (k) and data matrix (LR, T, LM), as arguments, and returns a scalar, which is the residual sum of squares. Then you can optimize

Re: [R] subject: Log likelihood above 0

2010-10-05 Thread Ravi Varadhan
, the log-likelihood cannot be positive. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu

Re: [R] subject: Log likelihood above 0

2010-10-05 Thread Ravi Varadhan
Yes, of course! So, the complete answer is: the log-likelihood can be in (-Inf, Inf), regardless of whether the random variable is continuous or discrete or mixed. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division

Re: [R] nonlinear curve fit of an implicit function

2010-10-05 Thread Ravi Varadhan
on A,B, and C, such as positivity, etc? If so, you need to incorporate them as well. You can take a look at the package alabama, which has 2 optimizers: `auglag' and `constrOptim.nl'. Hope this helps, Ravi. Ravi Varadhan, Ph.D

Re: [R] nonlinear curve fit of an implicit function

2010-10-05 Thread Ravi Varadhan
Note that we now have a constrained optimization problem in (n + 3) variables: y, A, B, and C; but we also have `n' constraints among these n+3 variables. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric

Re: [R] Trapezoid Rule

2010-10-08 Thread Ravi Varadhan
I appreciate your honesty, but this is not a forum for getting your homework done. There is a reason why your professor assigns homework, which is for you to learn. By getting us to solve your homework problems, you are defeating that purpose, and more importantly, you are wasting your time,

Re: [R] rsolnp- Error (Help!)

2009-09-28 Thread Ravi Varadhan
mistakes. Y1 - optim(par=p0, fn=opti, method=L-BFGS-B, lower=lCons, upper=uCons) Y2 - nlminb(start=p0, obj=opti, lower=lCons, upper=uCons) Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging

Re: [R] sinusoidal relationship

2009-10-07 Thread Ravi Varadhan
- a*sin(b*x) + eps plot(x, y, type=p) nls(y ~ a * sin(b*x), start=list(a=0.1, b=0.1)) Note that `nls' will fail to converge without the error term. Best, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor

Re: [R] Simulate negative skewed, fat-tailed distribution

2009-10-07 Thread Ravi Varadhan
Take a look at the `rstable' function in the stable package to simulate random deviates from a stable distribution. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division

Re: [R] Adapt function

2009-10-08 Thread Ravi Varadhan
), up = c(2,1), fun = ff) Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original

Re: [R] Nelder-Mead with output of simplex vertices

2009-10-10 Thread Ravi Varadhan
at the evolution of the simplex. I can send this to you, if you are interested. Ben - can you please send me your translation from NR? I would like to compare it to my function. Thanks in advance. Best, Ravi. Ravi Varadhan, Ph.D

Re: [R] Solving a nonlinear System of equations

2009-10-11 Thread Ravi Varadhan
There are two packages for solving nonlinear systems: one is the `BBsolve' function in the BB package, and the other is `nleqslv' in the nleqslv package. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division

Re: [R] Generating a stochastic matrix with a specified second dominant eigenvalue

2009-10-16 Thread Ravi Varadhan
and for values of e2 close to 1. Thanks for trying. Best, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University

Re: [R] AFT-model with time-dependent covariates

2009-10-20 Thread Ravi Varadhan
. Best, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email

Re: [R] Diffusion of particles inside a sphere

2009-10-22 Thread Ravi Varadhan
with a time-marching scheme such as Euler's or Runge-Kutta schemes. Hope this helps, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph

  1   2   3   4   5   6   7   >