Skip to content

Commit

Permalink
Merge branch 'development' of github.com:PredictiveEcology/fireSenseU…
Browse files Browse the repository at this point in the history
…tils into development
  • Loading branch information
eliotmcintire committed Dec 13, 2024
2 parents c00dc42 + c03a30f commit 898b344
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
26 changes: 15 additions & 11 deletions R/predictIgnition.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
#' Predictions from ignition model
#'
#' @param model formula of fitted model (`sim$fireSense_IgnitionFitted[["formula"]][-2]`)
#' @param model the model used to fit ingition data - must have a predict method
#' @param data data for prediction
#' @param coefs model coefficients (`sim$fireSense_IgnitionFitted$coef`)
#' @param rescaleFactor spatial rescaling factor when predicted and fitted data are at different scales.
#' Calculaed as: (predResolution/fitResolution)^2
#' Calculated as: (predResolution/fitResolution)^2
#' @param lambdaRescaleFactor If the data for fitting has been sampled for pseudo-absences,
#' this imposes a new baseline probability of fire occurrences, hence predictions need to be adjusted.
#' If the original fire prob. is (total no. fires)/(total no. fires + total no. absences), and the fire
#' probability imposed by sampling is (total no. fires)/(total no. fires + no. sampled pseudo-absences), to
#' adjust predicted values, one needs to multiply them by (total no. fires + no. sampled pseudo-absences/(total no. fires + total no. absences)
#' @param linkinv family link function (`sim$fireSense_IgnitionFitted$family$linkinv`)
#'
#' @return vector of predicted values.
#'
#' @export

predictIgnition <- function(model, data, coefs, rescaleFactor, lambdaRescaleFactor, linkinv) {
mm <- model.matrix(model, data)
pred <- mm %*% coefs
pred <- drop(pred)
pred <- linkinv(pred)
pred <- pred * rescaleFactor
pred * lambdaRescaleFactor
predictIgnition <- function(model, data, rescaleFactor, lambdaRescaleFactor) {

ignitions <- predict(model, newdata = data)
ignitions <- ignitions * rescaleFactor * lambdaRescaleFactor
return(ignitions)

# mm <- model.matrix(model, data)
# pred <- mm %*% coefs
# pred <- drop(pred)
# pred <- linkinv(pred)
# pred <- pred * rescaleFactor
# pred * lambdaRescaleFactor

}
17 changes: 3 additions & 14 deletions man/predictIgnition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 898b344

Please sign in to comment.