--
You received this message because you are subscribed to a topic in the Google Groups "unmarked" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/unmarked/q3FO84fbyGI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to unmarked+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
rasterFromXYZ () in the raster package also does this type of thing. You simply provide a matrix with 3 columns - the xy coordinates and then the predictions at each location.
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
If i understand what you have done correctly, i think this should be a _weighted_ mean (I.e. multiplying the model predictions by the model weights).
--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+unsubscribe@googlegroups.com.
Hi Norberello,I think should work. Have you tried it? If it doesn't work, you can cover your raster stack to a data.frame like this:mydat <- as.data.frame(myrast, xy=TRUE)Richard
On Wed, Jun 7, 2017 at 2:45 AM, Norberello A <norbe...@gmail.com> wrote:
Hi Richard,--I am aware this post is 5yr old and perhaps is dead, but has this been implemented already? I've got exactly the same problem today and if possible I don't want to go over the data.frame solution.Thanks for the answer in advance,N
On Monday, 29 October 2012 20:04:52 UTC+7, Richard Chandler wrote:Hi Pat,This hasn't been implemented yet. I'll put it on the to-do list. In the meantime, you can convert your raster data into a data.frame (rows are pixels, columns are covariate) and then supply that data.frame to predict().RichardOn Sat, Oct 27, 2012 at 2:46 PM, Patrick Johnson <patrickly...@gmail.com> wrote:
Hey everybody - what is the best way to make maps using model-averaged predictions in unmarked? I have had success making model-averaged predictions using a fitList on a dataframe (as spelled out in the reference manual), but when I tried using similar methods to apply to a raster layer (a RasterStack) I get the error:"Error in x[, "Predicted"] : object of type 'S4' is not subsettable"My models with the greatest AIC support include 4-6 environmental variables.Any advice would be appreciated, thanks!
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to unma...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Richard Chandler
Assistant Professor
Warnell School of Forestry and Natural Resources
University of Georgia
706-542-5815
chandlerlab.uga.edu
--
You received this message because you are subscribed to a topic in the Google Groups "unmarked" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/unmarked/q3FO84fbyGI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to unma...@googlegroups.com.
library(unmarked)library(raster)data(crossbill)data(Switzerland)
#Fit two models umf <- unmarkedFrameOccu(y=as.matrix(crossbill[,c("det991", "det992", "det993")]),siteCovs=crossbill[,c("ele", "forest")],obsCovs=list(date=crossbill[,c("date991", "date992", "date993")]))
sc <- scale(siteCovs(umf))siteCovs(umf) <- sc
fm.occu <- occu(~date ~ele + I(ele^2) + forest, umf)
fm.occu2 <- occu(~1~1, umf)
#Build newdata raster stackelevation <- rasterFromXYZ(Switzerland[,c("x","y","elevation")], crs="+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs")
forest <- rasterFromXYZ(Switzerland[,c("x","y","forest")], crs="+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs")
ele.s <- (elevation-1189)/640forest.s <- (forest-34.7)/27.7ef <- stack(ele.s, forest.s)names(ef) <- c("ele", "forest")
#Make fitlistfl = fitList(fm.occu,fm.occu2)
#New function for model-averaged prediction from a fitList using a raster inputpred_raster_fitlist <- function(object, type, newdata=NULL, backTransform = TRUE, appendData = FALSE, level=0.95){ #----Same as existing function fl <- object@fits ese <- lapply(fl, predict, type = type, newdata = newdata, backTransform = backTransform, level=level) #---------------------------------
if(class(newdata) == "RasterStack"){ if(!require(raster)) stop("raster package is required") ese <- lapply(ese, as.matrix) } #----Same as existing function E <- sapply(ese, function(x) x[,"Predicted"]) SE <- sapply(ese, function(x) x[,"SE"]) lower <- sapply(ese, function(x) x[,"lower"]) upper <- sapply(ese, function(x) x[,"upper"]) ic <- sapply(fl, slot, "AIC") deltaic <- ic - min(ic) wts <- exp(-deltaic / 2) wts <- wts / sum(wts) parav <- as.numeric(E %*% wts) seav <- as.numeric(sqrt(SE^2 + (E - parav)^2) %*% wts) out <- data.frame(Predicted = parav, SE = seav) out$lower <- as.numeric(lower %*% wts) out$upper <- as.numeric(upper %*% wts) #------------------------------
if(class(newdata) == "RasterStack"){ E.mat <- matrix(out[,1], dim(newdata)[1], dim(newdata)[2], byrow=TRUE) E.raster <- raster::raster(E.mat) raster::extent(E.raster) <- raster::extent(newdata) out.rasters <- list(E.raster) for(i in 2:ncol(out)) { i.mat <- matrix(out[,i], dim(newdata)[1], dim(newdata)[2], byrow=TRUE) i.raster <- raster::raster(i.mat) raster::extent(i.raster) <- raster::extent(newdata) out.rasters[[i]] <- i.raster } out.stack <- stack(out.rasters) names(out.stack) <- colnames(out) raster::crs(out.stack) <- raster::crs(newdata) return(out.stack) }}
#Generate model-averaged predictionraster_test <- pred_raster_fitlist(fl, type='state', newdata=ef)plot(raster_test)