我正在尝试使MultiStraussHardcore交互作用适合spatstat(流感)中的一个示例数据集。对于所有类型和点模式,我都保持相同的交互作用和硬核半径。我正在运行以下代码块:
library(spatstat)
library("optimbase")
flusubset <- flu[1:4]
typelist <- lapply(lapply(flusubset$pattern, marks), levels)
stopifnot(length(unique(typelist))==1)
num_marks <- length(typelist[[1]])
iradii <- 50*ones(num_marks)
hradii <- 3*ones(num_marks)
Int <- anylist()
for (i in 1:dim(flusubset)[1]) {
Int[[i]] <- MultiStraussHard(iradii=iradii, hradii=hradii)
}
Int <- as.hyperframe(Int)
multmodel <- mppm(pattern ~ 1, data=flusubset, interaction=Int)
每次我运行mppm时,都会出现以下错误
Error in (function (d, tx, tu, par) : data and model do not have the same possible levels of marks
我也包括了追溯。
12. stop("data and model do not have the same possible levels of marks")
11. (function (d, tx, tu, par) { r <- par$iradii h <- par$hradii ...
10. do.call(fun, usedargs)
9. do.call.matched(pairpot, list(d = matrix(, 0, 0), tx = marks(X)[integer(0)], tu = marks(P)[integer(0)], par = potpars))
8. evalPairPotential(X, U, EqualPairs, pairpot, potpars, Reach)
7. evaluate(X, P, E, interaction$pot, interaction$par, correction = correction, splitInf = splitInf, ..., Reach = Reach, precomputed = precomputed, savecomputed = savecomputed)
6. evalInterEngine(X = X, P = P, E = E, interaction = interaction, correction = correction, splitInf = splitInf, ..., precomputed = precomputed, savecomputed = savecomputed)
5. evalInteraction(X, P, E, interaction, correction, ..., splitInf = splitInf, precomputed = precomputed, savecomputed = savecomputed)
4. mpl.prepare(Q, X, P, trend, interaction, covariates, want.trend, want.inter, correction, rbord, "quadrature points", callstring, subsetexpr = subsetexpr, allcovar = allcovar, precomputed = precomputed, savecomputed = savecomputed, covfunargs = covfunargs, weightfactor = weightfactor, ...
3. mpl.engine(Q, trend = trend, interaction = interaction, ..., covariates = covariates, correction = correction, rbord = rbord, use.gam = use.gam, allcovar = allcovar, preponly = TRUE, forcefit = TRUE)
2. bt.frame(Yi, ~1, inter, ..., covariates = covariates, allcovar = TRUE, use.gam = use.gam, vnamebase = itags[j], vnameprefix = itags[j])
1. mppm(pattern ~ 1, data = flusubset, interaction = Int)
我尝试为每个单独的点模式用ppm拟合MultiStraussHardcore模型,但没有问题。我已经确认每个点模式的可能级别是相同的。我还验证了交互作用和铁心半径矩阵具有正确的尺寸(两个半径均为2x2),并且包含交互对象的超帧是正确的尺寸。谢谢!
答案 0 :(得分:0)
感谢您所描述的问题和可重现的示例。这对我来说很容易。
实际上,您发现了一个小错误(文档不一致)。如果在for循环中进行替换,您的代码将运行无错误
MultiStraussHard(iradii=iradii, hradii=hradii)
作者
typ <- levels(marks(flu$pattern[[1]]))
MultiStraussHard(iradii=iradii, hradii=hradii, types=typ)
MultiStraussHard
的文档说,参数types
是可选的,但目前仅对ppm
调用有效。我将看看是否有可能将类型的自动检测扩展到mppm
,以便您的原始代码将在以后的spatstat
版本中使用。
答案 1 :(得分:0)
此问题已在github repository的spatstat
的最新开发版本中得到解决