R Under development (unstable) (2024-02-19 r85946 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # land type, categorical variable > > library("geostatsp") Loading required package: Matrix Loading required package: terra terra 1.7.71 > data("swissRain") > swissRain = unwrap(swissRain) > swissAltitude = unwrap(swissAltitude) > swissLandType = unwrap(swissLandType) > swissBorder = unwrap(swissBorder) > > swissRain$lograin = log(swissRain$rain) > swissRain$elevation = extract(swissAltitude, swissRain, ID=FALSE) > swissAltitude[1:50,1:50] = NA > > swissRaster = rast(extent=ext(swissBorder), ncols=20, nrows=20, + crs=crs(swissRain)) > > > swissRain$land = extract(swissLandType, swissRain, ID=FALSE) > # get rid of land types with few observations > landTable = table(swissRain$land) > landTable = as.character(names(landTable)[landTable > 5]) > swissRain2 = swissRain[as.character(swissRain$land) %in% landTable, ] > swissRain2$land = factor(swissRain2$land, + levels = names(sort(table(swissRain2$land), decreasing=TRUE))[1:5]) > > swissFit3 = likfitLgm( + data=swissRain2, + formula=lograin~ elevation + land, + param=c(range=46500, nugget=0.05,shape=1, + anisoAngleDegrees=35, anisoRatio=12), + paramToEstimate = c("range","nugget", + "anisoAngleDegrees", "anisoRatio"), + parscale = c(range=5000,nugget=0.01, + anisoRatio=1,anisoAngleDegrees=5) + ) > > swissKrige3 = krigeLgm( + data=swissRain2[1:60,], + formula = swissFit3$model$formula, + param=swissFit3$param, + covariates = list(elevation = swissAltitude,land=swissLandType), + grid = swissRaster, expPred=TRUE) Warning message: In krigeLgm(data = swissRain2[1:60, ], formula = swissFit3$model$formula, : cant find coefficientslandWater bodies, landEvergreen needleleaf forest, landEvergreen broadleaf forest, landDeciduous needleleaf forest, landDeciduous broadleaf forest, landClosed shrublands, landOpen shrublands, landWoody savannas, landSavannas, landPermanent Wetlands, landSnow and ice, landBarren or sparsely vegetatedin param > > pdf("krige3.pdf") > plot(swissKrige3[["predict"]]) > plot(swissBorder, add=TRUE) > dev.off() null device 1 > > > > > swissRain2$landFac2 = as.character(swissRain2$land) > > swissFit5= likfitLgm(lograin~ elevation + landFac2, + data=swissRain2, + param=c(range=46500, nugget=0.05,shape=1, + anisoAngleDegrees=35, anisoRatio=12), + paramToEstimate = c("range","nugget", + "anisoAngleDegrees", "anisoRatio"), + parscale = c(range=5000,nugget=0.01, + anisoRatio=1,anisoAngleDegrees=5) + ) > > > swissKrige5 = krigeLgm(data=swissRain2[1:60,], + formula = swissFit5$model$formula, + param=swissFit5$param, + covariates = list(elevation = swissAltitude,landFac2=swissLandType), + grid = swissRaster,expPred=TRUE) Warning message: In krigeLgm(data = swissRain2[1:60, ], formula = swissFit5$model$formula, : cant find coefficientslandFac2Evergreen needleleaf forest, landFac2Evergreen broadleaf forest, landFac2Deciduous needleleaf forest, landFac2Deciduous broadleaf forest, landFac2Closed shrublands, landFac2Open shrublands, landFac2Woody savannas, landFac2Savannas, landFac2Permanent Wetlands, landFac2Cropland/natural vegetation mosaic, landFac2Snow and ice, landFac2Barren or sparsely vegetatedin param > pdf("krige5.pdf") > plot(swissKrige5[["predict"]]) > plot(swissBorder, add=TRUE) > dev.off() null device 1 > > > > > > > > proc.time() user system elapsed 5.26 0.23 5.43