R の spatstat パッケージの ppm() 関数を使用して、画像共変量を使用してポイント プロセスをモデル化しようとしています。spatstat で使用するためにラスタを im オブジェクトに変換しましたが、im を共変量として使用すると問題が発生しました。モデルで。ピクセル値は数値ですが、これらは実際にはさまざまなランドスケープ ゾーンのコードにすぎないため、問題の核心は、モデルがピクセル値を数値ではなく係数として読み取れるようにすることです。次の 2 つのアプローチを試しました (R コードとデータを以下に示します)。1 つ目は、ラスター オブジェクトを im オブジェクトに変換する前に、ラスター値を数値から係数に変換することです。as.factor() 関数を使用すると、値を係数に変換するという望ましい効果があるようです。しかし、この共変量で ppm モデルを実行すると、ppm() 関数には、モデルの各因子水準のパラメーターが含まれていません (参照水準と比較して)。むしろ、共変量を 1 つの共変量に対して 1 つのパラメーターのみを持つ数値として扱います。2 番目のアプローチは、共変量自体ではなく、式の引数で共変量を指定するために使用される factor(covariate) を使用して ppm モデルを実行することでした。これは実際にモデルをフィッティングする際に機能し、参照と比較した各因子レベルのパラメーターを提供します。ただし、式の引数で factor() を使用したため、予測を取得するために predict.ppm() を実行すると失敗します。質問は、共変量画像の値を因子として認識し、したがって、各因子レベルのパラメーター推定値 (参照を差し引いたもの) でモデルをフィッティングし、predict.ppm で予測できるように ppm モデルを実行するにはどうすればよいかということです。 ().
ポイント プロセス データはこちらの csv 形式です: https://www.dropbox.com/s/tp1opzsmc14e2hb/EbolaData_AnalyticSet_8.8.14.csv?dl=0
共変量の tiff ファイルはこちら: https://www.dropbox.com/s/0fyt0jflokrpp5z/anthrome2000_global_5min.tif?dl=0
そして、Rコードは次のとおりです。
library(raster)
library(spatstat)
library(geostatsp)
# First set the geographic extent we'll be using
e <- extent(-20, 60, -40, 35)
# Then read in the point process data in .csv file:
outbreaks <- read.csv("EbolaData_AnalyticSet_8.8.14.csv")
coordinates(outbreaks) <- ~Longitude+Latitude
proj4string(outbreaks) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
# Then read in the anthropogenic biome tiff and crop it
anthro2000 <- raster("anthrome2000_global_5min.tif")
anthro2000.africa <- crop(anthro2000, e)
# Then we define oour point process and window for spatstat:
SP <- as(outbreaks, "SpatialPoints")
outbreaks.ppp <- as(SP, "ppp")
# Now let's create a window
SP.win <- as(e, "SpatialPolygons")
W <- as(SP.win, "owin")
# Before creating the im object, let's convert the pixel values in raster to factor:
is.factor(anthro2000.africa)
f <- as.factor(anthro2000.africa)
is.factor(f)
rat <- levels(f)[[1]]
rat$anthro <- c("Urban", "Mixed Settle", "Rice Villages", "Irrigated villages", "Rainfed villages", "Pastoral vilalges",
"Resid. irrig. cropland", "Resid. rainfed cropland", "Pop. cropland", "Remote cropland",
"Resid. rangeland", "Pop. rangeland", "Remote rangeland", "Resid. forests", "Pop. forests",
"Remote forests", "Inhabited treeless and barren", "Wild forests", "Wild treeless and Barren")
rat$code <- c(11,12,21,22,23,24,31,32,33,34,41,42,43,51,52,53,54,61,62)
levels(f) <- rat
# Now let's convert that raster to an im object for use in spatstat:
anthro2000.africa.img <- asImRaster(f)
# Everything is now set up for the ppm models
# Aprroach 1
spatial.m.1 <- ppm(outbreaks.ppp, ~ Cov1, covariates = list(Cov1 = anthro2000.africa.img))
spatial.m.1 # Notice the model is fitted, however the pixel values of the covariate are not interepreted as factor
# Approach 2:
spatial.m.2 <- ppm(outbreaks.ppp, ~ factor(Cov1), covariates = list(Cov1 = anthro2000.africa.img)) # Noticce the use of factor() here to force the covariate as factor
spatial.m.2 # Here the model is fitted correctly with covariate as factor and thus each factor level has a parameter estimate in the model (relative to the ref)
# However, the approach does not allow me to run the predictions:
p <- predict.ppm(spatial.m.2, covariates = list(Cov1 = anthro2000.africa.img))