Re: [R] Problem in log

2011-11-30 Thread R. Michael Weylandt
You still haven't provided anything reproducible since we can't get to your data file (also you used the-you-really-shouldn't-use-this-function function attach) but here's what I'd guess: Your say the problem occurs when exp(-alpha*d^(-beta)) > 1 Of course, this happens when alpha*d^(-beta) < 0

Re: [R] Problem in log

2011-11-30 Thread Gyanendra Pokharel
The loglikelihood() looks ok and gives some value. But I am using this function for the simulated annealing, generating the random samples from uniform proposal density., The codes are as follows epiannea <- function(T0 = 1, N = 500,beta = 0.1,x0 = 0.1, rho = 0.90, eps = 0.1, loglikelihood, data)

Re: [R] Problem in log

2011-11-30 Thread R. Michael Weylandt
I'd suggest you do some leg-work and figure out why you are getting values >1. If your algorithm is motivated by some approximation then a min() or pmin() *might* be the right fix, but if there are no approximations you may need to start debugging properly to see why you are getting an out of bo

Re: [R] Problem in log

2011-11-29 Thread Sarah Goslee
On Tue, Nov 29, 2011 at 6:55 PM, Gyanendra Pokharel wrote: > yes, log of negative number is undefined and R also do the same and produces > NaNs. Here I want to reject the value of exp(-alpha*d^(-beta)) when greater > than 1, and want to run the loop otherwise. > Thanks Then just add another if()

Re: [R] Problem in log

2011-11-29 Thread Gyanendra Pokharel
yes, log of negative number is undefined and R also do the same and produces NaNs. Here I want to reject the value of exp(-alpha*d^(-beta)) when greater than 1, and want to run the loop otherwise. Thanks On Tue, Nov 29, 2011 at 6:48 PM, Sarah Goslee wrote: > > Here p[i] <- 1 - exp(-alpha*d^(-beta

Re: [R] Problem in log

2011-11-29 Thread Sarah Goslee
> Here p[i] <- 1 - exp(-alpha*d^(-beta))> so,  log(p[i]) produces NaNs when > exp(-alpha*d^(-beta)) is greater than 1.> How can I remove it.After > generating the out put we can omit it, but the> problem is different. Wait... you're complaining that you can't take the natural log of a negative n

Re: [R] Problem in log

2011-11-29 Thread Gyanendra Pokharel
I have following code: loglikelihood <- function(alpha,beta= 0.1){ loglh<-0 d<-0 p<-0 k<-NULL data<-read.table("epidemic.txt",header = TRUE) attach(data, warn.conflicts = F) k <-which(inftime==1) d <- (sqrt((x-x[k])^2+(y-y[k])^2))^(-beta) p<-1 - exp(-alpha*d)

Re: [R] Problem in log

2011-11-29 Thread Bert Gunter
Extension to the complex plane? -- Bert Hint: What does the graph of y = log(x) look like? On Tue, Nov 29, 2011 at 2:02 PM, Gyanendra Pokharel wrote: > Hi all I have a function of log defined by y = log(1- exp(-a)), when > exp(-a) is greater, 1, it produce NaN. How can I remove this in R? > >  

Re: [R] Problem in log

2011-11-29 Thread R. Michael Weylandt
Do you mean remove the NaNs? Try na.omit() or complete.cases() or many other options. If you mean you want the complex log, try log(as.complex(1-exp(-a))) Michael On Tue, Nov 29, 2011 at 5:02 PM, Gyanendra Pokharel wrote: > Hi all I have a function of log defined by y = log(1- exp(-a)), when >

[R] Problem in log

2011-11-29 Thread Gyanendra Pokharel
Hi all I have a function of log defined by y = log(1- exp(-a)), when exp(-a) is greater, 1, it produce NaN. How can I remove this in R? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listin