A couple of my functions that were working last week seem to have been
changed over the weekend and no longer work, but I can't understand why
not: it seems that objects defined at the start of the function are not
located further on in the function, when this worked fine before. An
example follows at the end, using the package spatstat, though the
problem seems more general. My only guess is that I've accidentally
changed something to do with the environment that functions are
searching in to exclude themselves, but if so I've no idea how I did or
how I can cancel it!
Thanks in advance,
Colin
library (spatstat)
kernelEst <- function (data, max.r = 10, edge = TRUE) {
if (!is.ppp (data)) stop ("data must be a point process object")
i <- 0.1
diff <- 1
smo <- 1
while (diff > 0) {
olddiff <- diff
oldsmo <- smo
smo <- density.ppp (data, sigma = 2 * i, edge = edge)
lambda <- smo[data]
Ki <- Kinhom (data[,data$window], lambda = lambda, r = seq (0,
max.r, length = 100), correction = "trans")
diff <- sum (Ki$theo - Ki$trans)
i <- i + 0.1
if (i > max.r) stop ("no suitable kernel found within 0.2 to
max.r")
}
if (abs (olddiff) > abs (diff)) return (smo) else return (oldsmo)
}
data (simdat)
test <- kernelEst (simdat)
Error in while (diff > 0) { : missing value where TRUE/FALSE needed
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 2.1
year 2005
month 12
day 20
svn rev 36812
language R
It does not say `unfound' it says `missing value'. See ?NA. Note it is the value and not the object that is said to be missing. Looks like on your data that one or more of the values you are summing is NA. On Tue, 18 Apr 2006, Colin Beale wrote:> A couple of my functions that were working last week seem to have been > changed over the weekend and no longer work, but I can't understand why > not: it seems that objects defined at the start of the function are not > located further on in the function, when this worked fine before. An > example follows at the end, using the package spatstat, though the > problem seems more general. My only guess is that I've accidentally > changed something to do with the environment that functions are > searching in to exclude themselves, but if so I've no idea how I did or > how I can cancel it! > > Thanks in advance, > > Colin > > > library (spatstat) > > kernelEst <- function (data, max.r = 10, edge = TRUE) { > > if (!is.ppp (data)) stop ("data must be a point process object") > > i <- 0.1 > diff <- 1 > smo <- 1 > > while (diff > 0) { > olddiff <- diff > oldsmo <- smo > smo <- density.ppp (data, sigma = 2 * i, edge = edge) > lambda <- smo[data] > Ki <- Kinhom (data[,data$window], lambda = lambda, r = seq (0, > max.r, length = 100), correction = "trans") > diff <- sum (Ki$theo - Ki$trans) > i <- i + 0.1 > if (i > max.r) stop ("no suitable kernel found within 0.2 to > max.r") > } > > if (abs (olddiff) > abs (diff)) return (smo) else return (oldsmo) > } > > data (simdat) > test <- kernelEst (simdat) > Error in while (diff > 0) { : missing value where TRUE/FALSE needed > > > >> version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 2.1 > year 2005 > month 12 > day 20 > svn rev 36812 > language R > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Colin,
Did you use correction = "trans" in Kinhom in the past? I think
Ki$trans will contain a number of NAs. Try
diff <- sum (Ki$theo - Ki$trans, na.rm = TRUE)
Peter Ehlers
Colin Beale wrote:> A couple of my functions that were working last week seem to have been
> changed over the weekend and no longer work, but I can't understand why
> not: it seems that objects defined at the start of the function are not
> located further on in the function, when this worked fine before. An
> example follows at the end, using the package spatstat, though the
> problem seems more general. My only guess is that I've accidentally
> changed something to do with the environment that functions are
> searching in to exclude themselves, but if so I've no idea how I did or
> how I can cancel it!
>
> Thanks in advance,
>
> Colin
>
>
> library (spatstat)
>
> kernelEst <- function (data, max.r = 10, edge = TRUE) {
>
> if (!is.ppp (data)) stop ("data must be a point process
object")
>
> i <- 0.1
> diff <- 1
> smo <- 1
>
> while (diff > 0) {
> olddiff <- diff
> oldsmo <- smo
> smo <- density.ppp (data, sigma = 2 * i, edge = edge)
> lambda <- smo[data]
> Ki <- Kinhom (data[,data$window], lambda = lambda, r = seq (0,
> max.r, length = 100), correction = "trans")
> diff <- sum (Ki$theo - Ki$trans)
> i <- i + 0.1
> if (i > max.r) stop ("no suitable kernel found within 0.2 to
> max.r")
> }
>
> if (abs (olddiff) > abs (diff)) return (smo) else return (oldsmo)
> }
>
> data (simdat)
> test <- kernelEst (simdat)
> Error in while (diff > 0) { : missing value where TRUE/FALSE needed
>
>
>
>
>>version
>
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 2.1
> year 2005
> month 12
> day 20
> svn rev 36812
> language R
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html