[R-sig-eco] Error in Kriging Procedure

Torsten Hauffe tor@ten@h@uffe @ending from gm@il@com
Fri Dec 14 17:50:44 CET 2018


Hi Alexandre,

looks like you are trying to apply inverse distance weighting with gstat.

For that your command should be something like this:

Model_ok  <- gstat( id='NMDS1_kri',  formula= NMDS1 ~ 1 , data = X)

Where X is a data.frame of your coordinates with NMDS scores or a spatial
object like your nmds_scores.

HTH,
Torsten

On Fri, 14 Dec 2018 at 17:38, Alexandre F. Souza <
alexsouza.cb.ufrn.br using gmail.com> wrote:

> Hello,
>
> I am new to interpolating techiques, and I am getting a persistent erro
> message I have not been able to resolve. I am trying to krig spatialized
> ordination scores into a raster of the Brazilian Atlantic Forest, as you
> can see below. I previously run a NMDS with 5 dimensions on species
> presence-absence data and saved the nmds scores. I send in attachment the
> atlantic forest shapefile and the nmds scores, to make the code more
> reproducible.
>
> # Convert NMDS-scores to SpatialPoints objects
> coords = as.data.frame(coords)
> names(coords) = c("longitude","latitude")
> nmds_scores<-cbind(coords, nmds_scores)
> coordinates(nmds_scores)<-~longitude+latitude # Convert 'nmds_scores'
> dataframe to SpatialPointsDataframe
> wgs84<-"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" #
> WGS84 Coordinate Reference System (CRS)
> crs(nmds_scores)<-wgs84 # Set the original CRS (WGS84)
> new_crs<-"+proj=robin +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m
> +no_defs" # Transform CRS to Robinson projection (it is necessary to have
> projected data for interpolation)
> nmds_scores<-spTransform(nmds_scores, new_crs)
>
>
> # Read the shapefile of Brazilian Atlantic Forest (BAF) and rasterize it
> BAF_limit<-readOGR("C:/Users/Augusto/Documents/MESTRADO/Projeto
> CAATINGA/Analise k-means/shapecaa")
> BAF_limit<-spTransform(BAF_limit, wgs84) # Change the CRS from SIRGAS2000
> to WGS84
> r_ext<-extent(BAF_limit)
> r<-raster() # Create a empty raster to receive data
> res(r)<-0.04166667 # Define raster resolution in decimal degrees (= 10
> arc-min)
> r<-crop(r, r_ext) # Define spatial extent of the raster (same as BAF)
> BAF_raster<-rasterize(BAF_limit, r, field=1, background=NA)
>
> # Get the spatial coordinates of BAF pixels
> get_coords<-rasterToPoints(BAF_raster)
> get_coords<-as.data.frame(get_coords[, c(1:2)])
> get_coords<-cbind(get_coords, NA, NA, NA)
> names(get_coords)<-c("longitude", "latitude", "NMDS1", "NMDS2", "NMDS3")
> coordinates(get_coords)<-~longitude+latitude # Convert 'get_coords'
> dataframe to SpatialPointsDataframe
> crs(get_coords)<-wgs84 # Set the original CRS (WGS84)
> get_coords<-spTransform(get_coords, new_crs) # Transform CRS to Robinson
> projection
>
> gModel_ok <- gstat(NULL, id='NMDS1_kri',
>                    formula= NMDS1 ~ 1,
>                    locations=coords, model=data.fit)
>
> G0y_ok <- interpolate(BAF_raster, gModel_ok, xyOnly=FALSE)
>
> Error in as(data, "data.frame") :
>   no method or default for coercing “NULL” to “data.frame”
>
>
> Do anyone has any idea of what may be wrong? I tried to empty the raster
> changing all vaues to zero but did not work.
>
> Thanks a log in advance,
>
> Alexandre
> --
> Dr. Alexandre F. Souza
> Professor Adjunto IV
> Chefe do Departamento de Ecologia
> Universidade Federal do Rio Grande do Norte
> CB, Departamento de Ecologia
> Campus Universitário - Lagoa Nova
> 59072-970 - Natal, RN - Brasil
> lattes: lattes.cnpq.br/7844758818522706
> http://www.esferacientifica.com.br
> http://www.docente.ufrn.br/alexsouza
> orcid.org/0000-0001-7468-3631 <http://www.docente.ufrn.br/alexsouza>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list