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
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)
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
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()
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
> 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
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)
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?
>
>
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
>
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
10 matches
Mail list logo