Verificar codigo corre –> Ya corre bien
Analisis mamiferos todos menos acuaticos y murcielagos. Herbivoros (sin carnivoros).
Enfocarnos en los faneine para comparar con todos los escarabajos. Volver a correr con solo faneine (cavadores).
GLMM con generos… pendiente
Data sets:
# fix coprofagos coordenates
#for(i in 1:nrow(coprofagos)){
copro_point<-as.data.frame(cbind(as.character(coprofagos[,7]),as.character(coprofagos[,8])))
colnames(copro_point)<- c("Lat" , "LoW")
copro_point2 <- ConvertToDD(XY = copro_point, LatColName = "Lat", LongColName = "LoW")
copro_point3 <- as.data.frame(ConvertToDD(XY = copro_point, LatColName = "Lat", LongColName = "LoW"))
# }
# change cord order
copro_point.coord<-cbind(copro_point3[,2],copro_point3[,1])
# pega puntos coprofagos en la tabla
coprofagos <- cbind(coprofagos, copro_point3)
coprofagos.info<-coprofagos[,c(-3,-4,-5,-6,-7,-8,-9)]
######SpatialPointsDataFrame
coprofagos.SPDF <- SpatialPointsDataFrame(copro_point.coord, coprofagos.info)
coprofagos.SPDF$binomial<-paste(coprofagos.SPDF$Genero, coprofagos.SPDF$Especie,sep = " ")
plot(co, border = "gray" )#, add = T)
points(copro_point3$DD.lon, copro_point3$DD.lat, col = "blue", cex = 0.5)## Marked planar point pattern: 2772 points
## Average intensity 29.82255 points per square unit
##
## *Pattern contains duplicated points*
##
## Coordinates are given to 6 decimal places
##
## Multitype:
## frequency proportion intensity
## E 268 0.0966811 2.883277
## P 1682 0.6067821 18.095790
## T 822 0.2965368 8.843483
##
## Window: polygonal boundary
## single connected closed polygon with 6640 vertices
## enclosing rectangle: [-79.05875, -66.87458] x [-4.225417, 12.467083] units
## Window area = 92.9498 square units
## Fraction of frame area: 0.457
##
## *** 40 illegal points stored in attr(,"rejects") ***
## tile
## 1 2 3 4 5
## 556 348 233 709 945
##
## Berman Z1 test of CSR in two dimensions
##
## data: covariate 'mydata4' evaluated at points of 'copro.ppp.unmark'
## Z1 = 9.5436, p-value < 2.2e-16
## alternative hypothesis: two-sided
##
## Berman Z1 test of CSR in two dimensions
##
## data: covariate 'mammal.diver4' evaluated at points of 'copro.ppp.unmark'
## Z1 = 5.7982, p-value = 6.703e-09
## alternative hypothesis: two-sided
## Model diagnostics (raw residuals)
## Diagnostics available:
## smoothed residual field
## range of smoothed field = [-22.44, 40.47]
## Extracting model information...Evaluating trend...done.
## Simulating 30 realisations... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
##
## Diagnostic info:
## simulated patterns contained an average of 2725.8 points.
## Calculating quantiles...averaging.....Done.
## Model diagnostics (raw residuals)
## Diagnostics available:
## four-panel plot
## mark plot
## smoothed residual field
## x cumulative residuals
## y cumulative residuals
## sum of all residuals
## sum of raw residuals in entire window = -1.609e-06
## area of entire window = 92.95
## quadrature area = 92.79
## range of smoothed field = [-22.44, 40.47]
## Model diagnostics (raw residuals)
## Diagnostics available:
## four-panel plot
## mark plot
## smoothed residual field
## x cumulative residuals
## y cumulative residuals
## sum of all residuals
## sum of raw residuals in entire window = -1.609e-06
## area of entire window = 92.95
## quadrature area = 92.79
## range of smoothed field = [-22.44, 40.47]
##################################################################
################ sub set window
##################################################################
x2range=c(-77, -72)
y2range=c(3, 7.5)
winsubset <- owin(c(-77, -72.5),c(3, 7)) # the subwindow
# trim dataset to this subwindow
copro.subset <- copro.ppp[,winsubset]
# mammal.subset <- mammal.ppp[,winsubset]
# plot(alt)
plot(copro.subset)
plot(mydata4, add=T) # mapa mammal density
plot(mammal.diver4, add=T) # mapa mammal density detailed
plot(copro.subset, add=T, pch="o")
#plot(mammal.subset, add=T, pch = "+")
plot(co, border = "gray", add = T)# mammal.density.m <- mask(mammal.density, m)
# plot(mammal.density) # mapa mammal density
# mammal.density.subset<-as.im(density.ppp(mammal.ppp,edge = T),W=winsubset)
########## get detailed alti
########## alt.detail has the full alti extent
altidata2<-as(alt.detail, "SpatialGridDataFrame")
altidata3<-as.image.SpatialGridDataFrame(altidata2)
rm(altidata2) # make room in memory
altidata4<-as.im(altidata3, winsubset)
m <- as.mask(altidata4)
altidata4<-as.im(mydata3, as.polygonal(m))
# alt.subset<-as.im(alt.detail,W=winsubset)
mammal.diver.subset<-as.im(mammal.diver4,W=winsubset)
copro.subset.unmarked <- unmark(copro.subset)# unmark copro subset
# plot(alt)
plot(mammal.diver.subset)
# plot(mydata4, add=T) # mapa mammal density
plot(copro.subset, add=T, pch="+")
#plot(mammal.subset, add=T, pch = "+")
plot(co, border = "gray", add = T)###########################
# models
##########################
fit11<- ppm(copro.subset.unmarked ~ 1 + mammal.diver.subset ,Poisson() ) # Mamiferos ## Warning: Values of the covariate 'mammal.diver.subset' were NA or
## undefined at 0.08% (5 out of 5991) of the quadrature points. Occurred
## while executing: ppm.ppp(Q = copro.subset.unmarked, trend = ~1 +
## mammal.diver.subset,
fit12<- ppm(copro.subset.unmarked ~ 1 + altidata4 ,Poisson() ) # altitud
fit13<- ppm(copro.subset.unmarked ~ mammal.diver.subset + altidata4 ,Poisson() ) # Mamiferos altitud## Warning: Values of the covariate 'mammal.diver.subset' were NA or
## undefined at 0.08% (5 out of 5991) of the quadrature points. Occurred while
## executing: ppm.ppp(Q = copro.subset.unmarked, trend = ~mammal.diver.subset
## +
fit14<- ppm(copro.subset.unmarked ~ altidata4 + mammal.diver.subset ,Poisson() ) # Mamiferos altitud## Warning: Values of the covariate 'mammal.diver.subset' were NA or
## undefined at 0.08% (5 out of 5991) of the quadrature points. Occurred
## while executing: ppm.ppp(Q = copro.subset.unmarked, trend = ~altidata4 +
## mammal.diver.subset,
## [1] -6781.463
## [1] -6753.597
## [1] -6816.498
## [1] -6816.498
## Warning: Some infinite, NA or NaN increments were removed
## Model diagnostics (raw residuals)
## Diagnostics available:
## four-panel plot
## mark plot
## smoothed residual field
## x cumulative residuals
## y cumulative residuals
## sum of all residuals
## sum of raw residuals in entire window = -6.95e-08
## area of entire window = 18
## quadrature area = 17.99
## range of smoothed field = [-51.3, 54.76]
## Point process model
## Fitting method: maximum likelihood (Berman-Turner approximation)
## Model was fitted using glm()
## Algorithm converged
## Call:
## ppm.formula(Q = copro.subset.unmarked ~ altidata4 + mammal.diver.subset,
## interaction = Poisson())
## Edge correction: "border"
## [border correction distance r = 0 ]
## ---------------------------------------------------------------------------
## Quadrature scheme (Berman-Turner) = data + dummy + weights
##
## Data pattern:
## Planar point pattern: 1087 points
## Average intensity 60.4 points per square unit
## Window: rectangle = [-77, -72.5] x [3, 7] units
## Window area = 18 square units
##
## Dummy quadrature points:
## 70 x 70 grid of dummy points, plus 4 corner points
## dummy spacing: 0.06428571 x 0.05714286 units
##
## Original dummy parameters: =
## Planar point pattern: 4904 points
## Average intensity 272 points per square unit
## Window: rectangle = [-77, -72.5] x [3, 7] units
## Window area = 18 square units
## Quadrature weights:
## (counting weights based on 70 x 70 array of rectangular tiles)
## All weights:
## range: [0.000105, 0.00367] total: 18
## Weights on data points:
## range: [0.000105, 0.00184] total: 0.562
## Weights on dummy points:
## range: [0.000105, 0.00367] total: 17.4
## ---------------------------------------------------------------------------
## FITTED MODEL:
##
## Nonstationary Poisson process
##
## ---- Intensity: ----
##
## Log intensity: ~altidata4 + mammal.diver.subset
## Model depends on external covariates 'altidata4' and 'mammal.diver.subset'
## Covariates provided:
## altidata4: im
## mammal.diver.subset: im
##
## Fitted trend coefficients:
## (Intercept) altidata4 mammal.diver.subset
## 3.7360692244 -0.0002044439 0.0101032944
##
## Estimate S.E. CI95.lo CI95.hi
## (Intercept) 3.7360692244 7.847779e-02 3.5822555882 3.8898828605
## altidata4 -0.0002044439 3.492441e-05 -0.0002728945 -0.0001359934
## mammal.diver.subset 0.0101032944 1.146540e-03 0.0078561176 0.0123504712
## Ztest Zval
## (Intercept) *** 47.606710
## altidata4 *** -5.853898
## mammal.diver.subset *** 8.811987
##
## ----------- gory details -----
##
## Fitted regular parameters (theta):
## (Intercept) altidata4 mammal.diver.subset
## 3.7360692244 -0.0002044439 0.0101032944
##
## Fitted exp(theta):
## (Intercept) altidata4 mammal.diver.subset
## 41.9328372 0.9997956 1.0101545
## Problem:
## Values of the covariate 'mammal.diver.subset' were NA or undefined at 0.08% (5 out of 5991) of the quadrature points
intensity <- predict(fit14, type="intensity")
## Not run:
image(intensity)
points(copro.subset.unmarked)###################################
# remove duplicates
# Drugs <- data.London[data.London$Crime.type==unique(data.London$Crime.type)[3],]
# Drugs <- remove.duplicates(Drugs)Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.