I'm working with spatstat 2.3-4 in R 4.1.0 on a 64bit windows 10 pro machine.
Recently I ran into the integer-overflow error while using Kcross with a large number of points (i.e. the number of combination exceeded .Machine$integer.max). For example:
W <- as.owin(list(xrange = c(688.512, 17879.746) , yrange = c(-27996.842, -7759.813)))
cells1 <- runifpoint(n = 8062, win = W)
cells2 <- runifpoint(n = 1768988, win = W)
cells3 <- superimpose(tumor = cells1 , bcell = cells2)
Kcross(cells3 , r = seq(0,200,by=5) , "tumor" , "bcell" , correction="none") # error
# Error in if (nXY <= 1024) { : missing value where TRUE/FALSE needed
# In addition: Warning message: In nX * nY : NAs produced by integer overflow
8062 * 1768988 > .Machine$integer.max
# [1] TRUE
After a lot of struggling I realized that the error comes from this part of crosspairs:
if (spatstat.options("crosspairs.newcode")) {
nXY <- nX * nY
if (nXY <= 1024) {
nsize <- 1024
}
I could "fix" the error by changing spatstat options: spatstat.options("crosspairs.newcode" = FALSE).
Is this the way to deal with the error?
UPDATE:
As Adrian.Baddeley answered below, there is now a new spatstat.geom version on GitHub (currently: v2.4.-0.029) in which the bug is fixed. The new version works fine without the change of the options.
The bug is fixed in the development version of spatstat.geom available at the GitHub repository
This is a bug in some relatively new code to speed up the underlying function crosspairs.ppp(). Until a new version of spatstat.geom is available you can workaround the problem by setting spatstat.options("crosspairs.newcode" = FALSE) as suggested.
Related
Error in UseMethod("QuinlanAttributes") :
no applicable method for 'QuinlanAttributes' applied to an object of class "logical"
I am getting this error whenever I am running a code. I have installed several packages but this error is keep on repitiating.
it seems that C50 does not accept BOOLEAN features.
you can simpliy drop that column or replace BOOLEAN to 0/1.
if "tdata$Windy" is the BOOLEAN feature, replace the value of it.
library(C50)
tdata = read.csv('play.csv', header = TRUE, sep = ",")
xdata <- data.frame(tdata$Outlook,tdata$Temperature, tdata$Humidity, tdata$Windy)
ydata <- tdata$Play
treeModel <- C5.0(x = xdata, y = ydata )
summary(treeModel)
It's old question but I had same issue today and realized it's was due to read_sav().
I solved applying haven::as_factor to columns that should be factors.
data <- read_sav("datafile.sav")
data <- mutate(data, across(ends_with("_fct"), haven::as_factor ))
I am trying to use Brightway's ParallelMonteCarloand MultiMonteCarloclass but have run into a KeyError. I am in a Brightway project with an LCI database:
In [1] bw.databases
Out [1] Brightway2 databases metadata with 2 objects:
biosphere3
ecoinvent 3_2 CutOff
Selecting an activity and a method:
In [2] db = bw.Database('ecoinvent 3_2 CutOff')
act = db.random()
method = ('CML 2001', 'climate change', 'GWP 100a')
My code is as follows:
In [3] ParallelMC_LCA = bw.ParallelMonteCarlo({act:1},
method = myMethod,
iterations=1000,
cpus=mp.cpu_count())
results = np.array(ParallelMC_LCA.calculate())
and
In [4] act1 = db.random()
act2 = db.random()
multiMC_LCA = bw.MultiMonteCarlo(demands = [{act1:1}, {act2:1}],
method = myMethod,
iterations = 10)
results = np.array(ParallelMC_LCA.calculate())
Both give me a KeyError: 'ecoinvent 3_2 CutOff'.
My question is: why?
This is a known issue due to differences in how multiprocessing works on Windows and Unix. Specifically, on Windows the project is not set correctly, causing a KeyError. As such, it isn't a Stack Overflow question.
I have encountered an error message in an R Program (see code\details below) when I tried to use igraph library in my Xubuntu VM. This problem did not happen before . Everything was working just fine.
It started very recently when I was trying to re-set-up R\igraph in another new VM(Xubuntu) of mine.
Can anybody give me any kind of advice regarding how to fix this problem?
Below are the Details -
Error Message -
Attaching package: ‘igraph’
The following objects are masked from ‘package:stats’:
decompose, spectrum
The following object is masked from ‘package:base’:
union
Loading required package: methods
Attaching package: ‘igraph’
The following objects are masked from ‘package:stats’:
decompose, spectrum
The following object is masked from ‘package:base’:
union
How I installed R Base & Igraph -
sudo apt-get -y install r-base
sudo echo "r <- getOption('repos'); r['CRAN'] <- 'http://cran.us.r- project.org'; options(repos = r);" > ~/.Rprofile
sudo Rscript -e "install.packages('ggplot2')"
sudo Rscript -e "install.packages('plyr')"
sudo Rscript -e "install.packages('reshape2')"
sudo Rscript -e "install.packages('igraph')"
sudo Rscript -e "install.packages('doBy')"
sudo Rscript -e "install.packages('stargazer')"
My R - Program
library(igraph)
g <- read.graph("DataForImage.net", format="pajek")
g <- delete.vertices(g,which(degree(g)<1))
jpeg(filename = "Image1.jpg", width = 2000, height = 2000,
units = "px", pointsize = 10, bg = "white",
res = NA)
g <- simplify(g)
l <- layout.fruchterman.reingold(g, dim=2,verbose=TRUE)
l <- layout.norm(l, -1,1, -1,1)
fcs <- fastgreedy.community(simplify(as.undirected(g)))
Q <- round(max(fcs$modularity), 3)
fcs <- community.to.membership(g, fcs$merges, steps=which.max(fcs$modularity)-1 )
plot(g, layout=l,vertex.shape="circle", vertex.size=2, vertex.label=NA, vertex.color="black",
vertex.frame.color="black", edge.width=5,
rescale=FALSE, xlim=range(l[,1]), ylim=range(l[,2]),
main="")
results <- read.table("detailTotals.csv", header=TRUE, sep=",")
jpeg(filename = "Image2.jpg", width = 2000, height = 2000,
units = "px", pointsize = 50, bg = "white",
res = NA)
plot(results$SetLineTotal, results$SetCount, main="Set Analysis",
xlab="Set Lines", ylab="Set Counts", col="black", bg="black", pch=21, cex=1)
grid(nx = 50, ny = 50, col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)
I thought I will share the final solution that seems to work for me.
I digged down a bit and upon some analysis , I found out the below.
The error seems to be with the igraph version - V1.0. The code statement in above R - program
l <- layout.fruchterman.reingold(g, dim=2,verbose=TRUE)
errors out in igraph V1.0.
The R-igraph package is re-written - and thereby some of the functions\network algorithms from older version is replaced\re-coded\modified in newer igraph version - 1.0 onwards.
So I reverted back to an older igraph package (0.7.1) and now I am no more facing the issue. And my R-program seems to work fine.
Below are the commands to revert to an older igraph package 0.7.1
wget http://cran.r-project.org/src/contrib/Archive/igraph/igraph_0.7.1.tar.gz
sudo R CMD INSTALL igraph_0.7.1.tar.gz
from fipy import *
nx = 50
dx = 1.
mesh = Grid1D(nx=nx, dx=dx)
phi = CellVariable(name="solution variable",
mesh=mesh,
value=0.)
D = 1.
valueLeft = 1
valueRight = 0
phi.constrain(valueRight, mesh.facesRight)
phi.constrain(valueLeft, mesh.facesLeft)
eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D)
timeStepDuration = 0.9 * dx**2 / (2 * D)
steps = 100
phiAnalytical = CellVariable(name="analytical value",
mesh=mesh)
viewer = Viewer(vars=(phi, phiAnalytical),
datamin=0., datamax=1.)
viewer.plot()
x = mesh.cellCenters[0]
t = timeStepDuration * steps
try:
from scipy.special import erf
phiAnalytical.setValue(1 - erf(x / (2 * numerix.sqrt(D * t))))
except ImportError:
print "The SciPy library is not available to test the solution to \
the transient diffusion equation"
for step in range(steps):
eqX.solve(var=phi,
dt=timeStepDuration)
viewer.plot()
I am trying to implement an example from the fipy examples list which is the 1D diffusion problem. but I am not able to view the result as a plot.
I have defined viewer correctly as suggested in the code for the example. Still not helping.
The solution vector runs fine.
But I am not able to plot using the viewer function. can anyone help? thank you!
Your code works fine on my computer. Probably is a problem with a plotting library used by FiPy.
Check if the original example works (just run this from the fipy folder)
python examples/diffusion/mesh1D.py
If not, download FiPy from the github page of the project https://github.com/usnistgov/fipy and try the example again. If not, check if the plotting libraries are correctly installed.
Anyways, you should specify the platform you are using and the errors you are getting. The first time I had some problems with the plotting libraries too.
I have made some changes to the lmer. It works as it should but I could not get rid of the warning message that pops when I run the program. I have added the following options which allows the program run without stopping but with the warning message. I believe it is the check.nobs.vs.rankZ = "warningSmall" part. How could I get rid of this, any suggestions? Thank you.
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"warningSmall",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),check.scaleX = "ignore",check.formula.LHS="ignore",
## convergence checking options
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL),
check.conv.singular = .makeCC(action = "ignore", tol = 1e-4),
check.conv.hess = .makeCC(action = "warning", tol = 1e-6)
Warning Message from R:
Warning message:
In checkZrank(reTrms$Zt, n = n, control, nonSmall = 1e+06) :
number of observations (=300) <= rank(Z) (=300); the random-effects parameters and the
residual variance (or scale parameter) are probably unidentifiable
You should try check.nobs.vs.rankZ="ignore".
lmerControl doesn't need to specify anything other than the non-default options: at a quick glance, these are your non-default values:
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"ignore",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),
check.scaleX = "ignore",
check.formula.LHS="ignore",
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL))
In general I would suggest it's wise to turn off only the specific warnings and errors you know you want to override -- the settings above look like they could get you in trouble.
I haven't checked this since you didn't give a reproducible example ...