R/Rescaler4.R

`.Rescaler4` <-
function(dataToRescale, ref=NULL, run, original=FALSE)
{
    #preparing data
    #homogenize the format accross original predictions and new projections 
    if(!class(dataToRescale)[1]=='RasterLayer'){
        DataF <- as.data.frame(dataToRescale)         
        colnames(DataF) <- "DataF"                  
    } else{
        layerNames(dataToRescale) <-"DataF"
	      DataF <- stack(dataToRescale) 
    }
    
    #Creating or loading the rescaling model
    if(original){ 
        Rescaling_GLM = glm(ref~DataF, data=DataF, family="binomial")
        eval(parse(text=paste("save(Rescaling_GLM, file='", getwd(), "/models/rescaling_models/Rmod_", run, "', compress='xz')", sep=""))) 
    } else
        eval(parse(text=paste("load('", getwd(), "/models/rescaling_models/Rmod_", run, "')", sep="")))
	 	
    #make the rescaling prediction
    if(!class(dataToRescale)[1]=='RasterLayer') RescaledData <- predict(Rescaling_GLM, DataF, type="response") 
	if(class(dataToRescale)[1]=='RasterLayer')  RescaledData <- predict(model=Rescaling_GLM, DataF, type="response")    #rasters
	   
   
    return(RescaledData)
}

Try the BIOMOD package in your browser

Any scripts or data that you put into this service are public.

BIOMOD documentation built on May 2, 2019, 6:48 p.m.