{"id":609,"date":"2014-04-21T15:58:13","date_gmt":"2014-04-21T20:58:13","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=609"},"modified":"2014-04-21T15:58:13","modified_gmt":"2014-04-21T20:58:13","slug":"performs-an-automatic-interpolation","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/04\/21\/performs-an-automatic-interpolation\/","title":{"rendered":"Performs an automatic interpolation"},"content":{"rendered":"<table style=\"color: #000000;\" summary=\"page for autoKrige\" width=\"100%\">\n<tbody>\n<tr>\n<td>autoKrige<\/td>\n<td align=\"right\">R Documentation<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"color: #000000;\">Performs an automatic interpolation<\/h2>\n<h3 style=\"color: #000000;\">Description<\/h3>\n<p style=\"color: #000000;\">This function performs automatic kriging on the given dataset. The variogram is generated automatically using autofitVariogram.<\/p>\n<h3 style=\"color: #000000;\">Usage<\/h3>\n<pre style=\"color: #000000;\">autoKrige(formula, \n  \t  input_data, \n\t  new_data, \n \t  data_variogram = input_data, \n\t  block = 0, \n\t  model = c(\"Sph\", \"Exp\", \"Gau\", \"Ste\"), \n\t  kappa = c(0.05, seq(0.2, 2, 0.1), 5, 10), \n\t  fix.values = c(NA,NA,NA), \n\t  remove_duplicates = TRUE, \n\t  verbose = FALSE, \n\t  GLS.model = NA,\n      start_vals = c(NA,NA,NA),\n      miscFitOptions = list(),\n\t  ...)<\/pre>\n<h3 style=\"color: #000000;\">Arguments<\/h3>\n<table style=\"color: #000000;\" summary=\"R argblock\">\n<tbody>\n<tr valign=\"top\">\n<td><code>formula<\/code><\/td>\n<td>formula that defines the dependent variable as a linear model of independent variables; suppose the dependent variable has name &#8216;z&#8217;, for ordinary and simple kriging use the formula &#8216;z~1&#8217;; for simple kriging also define &#8216;beta&#8217; (see below); for universal kriging, suppose &#8216;z&#8217; is linearly dependent on &#8216;x&#8217; and &#8216;y&#8217;, use the formula &#8216;z~x+y&#8217;.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>input_data<\/code><\/td>\n<td>An object of the SpatialPointsDataFrame-class containing the data to be interpolated.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>new_data<\/code><\/td>\n<td>A\u00a0<code>sp<\/code>\u00a0object containing the prediction locations.\u00a0<code>new_data<\/code>\u00a0can be a points set, a grid or a polygon. Must not contain NA&#8217;s. If this object is not provided a default is calculated. This is done by taking the convex hull of<code>input_data<\/code>\u00a0and placing around 5000 gridcells in that convex hull.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>data_variogram<\/code><\/td>\n<td>An optional way to provide a different dataset for the building of the variogram then for the spatial interpolation.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>block<\/code><\/td>\n<td>Use this parameter to pass on a specification for the block size. e.g. c(1000,1000)<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>model<\/code><\/td>\n<td>List of models that will be tested during automatic variogram fitting.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>kappa<\/code><\/td>\n<td>List of values for the smoothing parameter of the Matern model that will be tested during automatic variogram fitting.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>fix.values<\/code><\/td>\n<td>Can be used to fix a variogram parameter to a certain value. It consists of a list with a length of three. The items describe the fixed value for the nugget, range and sill respectively. Setting the value to NA means that the value is not fixed. Is passed on to autofitVariogram.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>remove_duplicates<\/code><\/td>\n<td>logical, remove duplicate points from the\u00a0<code>input_data<\/code>. This can take some time on large datasets.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>verbose<\/code><\/td>\n<td>logical, if TRUE autoKrige will give extra information on the fitting process<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>GLS.model<\/code><\/td>\n<td>If a variogram model is passed on through this parameter a Generalized Least Squares sample variogram is calculated.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>start_vals<\/code><\/td>\n<td>Can be used to give the starting values for the variogram fitting. The items describe the fixed value for the nugget, range and sill respectively. They need to be given in that order. Setting the value to NA means that the value will be automatically chosen.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>miscFitOptions<\/code><\/td>\n<td>Additional options to set the behavior of autofitVariogram. For details see the documentation of autofitVariogram.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>...<\/code><\/td>\n<td>arguments that are passed on to the gstat function\u00a0<code>krige<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 style=\"color: #000000;\">Details<\/h3>\n<p style=\"color: #000000;\"><code>autoKrige<\/code>\u00a0calls the function\u00a0<code>autofitVariogram<\/code>\u00a0that fits a variogram model to the given dataset. This variogram model and the data are used to make predictions on the locations in\u00a0<code>new_data<\/code>. The only compulsory argument is\u00a0<code>input_data<\/code>. So the most simple call would of the form:<\/p>\n<p style=\"color: #000000;\"><code>autoKrige(meuse)<\/code><\/p>\n<p style=\"color: #000000;\"><code>autoKrige<\/code>\u00a0now assumes that you want to perform ordinary kriging on the first column of\u00a0<code>input_data<\/code>.<\/p>\n<p style=\"color: #000000;\"><code>autoKrige<\/code>\u00a0performs some checks on the coordinate systems of\u00a0<code>input_data<\/code>\u00a0and\u00a0<code>new_data<\/code>. If one of both is\u00a0<code>NA<\/code>, it is assigned the projection of the other. If they have different projections, an error is raised. If one of both has a non-projected system (i.e. latitude-longitude), an error is raised. This error is raised because &#8216;gstat does use spherical distances when data are in geographical coordinates, however the usual variogram models are typically not non-negative definite on the sphere, and no appropriate models are available&#8217; (Edzer Pebesma on r-sig-geo).<\/p>\n<p style=\"color: #000000;\">When the user specifies the power model (<code>Pow<\/code>) as the model, the initial range is set to one. Note that when using the power model, the initial range is the initial power.<\/p>\n<h3 style=\"color: #000000;\">Value<\/h3>\n<p style=\"color: #000000;\">This function returns an\u00a0<code>autoKrige<\/code>\u00a0object containing the results of the interpolation (prediction, variance and standard deviation), the sample variogram, the variogram model that was fitted by\u00a0<code>autofitVariogram<\/code>\u00a0and the sums of squares between the sample variogram and the fitted variogram model. The attribute names are\u00a0<code>krige_output<\/code>,\u00a0<code>exp_var<\/code>,\u00a0<code>var_model<\/code>\u00a0and\u00a0<code>sserr<\/code>\u00a0respectively.<\/p>\n<h3 style=\"color: #000000;\">Author(s)<\/h3>\n<p style=\"color: #000000;\">Paul Hiemstra,\u00a0<a style=\"color: #708090;\" href=\"mailto:paul@numbertheory.nl\">paul@numbertheory.nl<\/a><\/p>\n<h3 style=\"color: #000000;\">See Also<\/h3>\n<p style=\"color: #000000;\"><code>autofitVariogram<\/code>,\u00a0<code>krige<\/code><\/p>\n<h3 style=\"color: #000000;\">Examples<\/h3>\n<pre style=\"color: #000000;\"># Data preparation\ndata(meuse)\ncoordinates(meuse) =~ x+y\ndata(meuse.grid)\ngridded(meuse.grid) =~ x+y\n\n# Ordinary kriging, no new_data object\nkriging_result = autoKrige(zinc~1, meuse)\nplot(kriging_result)\n\n# Ordinary kriging\nkriging_result = autoKrige(zinc~1, meuse, meuse.grid)\nplot(kriging_result)\n\n# Fixing the nugget to 0.2\nkriging_result = autoKrige(zinc~1, meuse, \n\tmeuse.grid, fix.values = c(0.2,NA,NA))\nplot(kriging_result)\n\n# Universal kriging\nkriging_result = autoKrige(zinc~soil+ffreq+dist, meuse, meuse.grid)\nplot(kriging_result)\n\n# Block kriging\nkriging_result_block = autoKrige(zinc~soil+ffreq+dist, \n\tmeuse, meuse.grid, block = c(400,400))\nplot(kriging_result_block)\n\n# Dealing with duplicate observations\ndata(meuse)\nmeuse.dup = rbind(meuse, meuse[1,]) # Create duplicate\ncoordinates(meuse.dup) = ~x+y\nkr = autoKrige(zinc~dist, meuse.dup, meuse.grid)\n\n# Extracting parts from the autoKrige object\nprediction_spdf = kr$krige_output\nsample_variogram = kr$exp_var\nvariogram_model = kr$var_model\n<\/pre>\n<h3 style=\"color: #000000;\">Results<\/h3>\n<pre style=\"color: #000000;\">R version 3.0.2 (2013-09-25) -- \"Frisbee Sailing\"\nCopyright (C) 2013 The R Foundation for Statistical Computing\nPlatform: x86_64-unknown-linux-gnu (64-bit)\n\nR is free software and comes with ABSOLUTELY NO WARRANTY.\nYou are welcome to redistribute it under certain conditions.\nType 'license()' or 'licence()' for distribution details.\n\nR is a collaborative project with many contributors.\nType 'contributors()' for more information and\n'citation()' on how to cite R or R packages in publications.\n\nType 'demo()' for some demos, 'help()' for on-line help, or\n'help.start()' for an HTML browser interface to help.\nType 'q()' to quit R.\n\n&gt; library(automap)\nLoading required package: sp\nLoading required package: gstat\n&gt; png(filename=\"\/home\/oogasawa\/snapshot\/RGM3\/R_CC\/result\/automap\/autoKrige.rd_%03d_medium.png\", width=480, height=480)\n&gt; ### Name: autoKrige\n&gt; ### Title: Performs an automatic interpolation\n&gt; ### Aliases: autoKrige\n&gt; \n&gt; ### ** Examples\n&gt; \n&gt; # Data preparation\n&gt; data(meuse)\n&gt; coordinates(meuse) =~ x+y\n&gt; data(meuse.grid)\n&gt; gridded(meuse.grid) =~ x+y\n&gt; \n&gt; # Ordinary kriging, no new_data object\n&gt; kriging_result = autoKrige(zinc~1, meuse)\n[using ordinary kriging]\n&gt; plot(kriging_result)\n&gt; \n&gt; # Ordinary kriging\n&gt; kriging_result = autoKrige(zinc~1, meuse, meuse.grid)\n[using ordinary kriging]\n&gt; plot(kriging_result)\n&gt; \n&gt; # Fixing the nugget to 0.2\n&gt; kriging_result = autoKrige(zinc~1, meuse, \n+ \tmeuse.grid, fix.values = c(0.2,NA,NA))\n[using ordinary kriging]\n&gt; plot(kriging_result)\n&gt; \n&gt; # Universal kriging\n&gt; kriging_result = autoKrige(zinc~soil+ffreq+dist, meuse, meuse.grid)\n[using universal kriging]\n&gt; plot(kriging_result)\n&gt; \n&gt; # Block kriging\n&gt; kriging_result_block = autoKrige(zinc~soil+ffreq+dist, \n+ \tmeuse, meuse.grid, block = c(400,400))\n[using universal kriging]\n&gt; plot(kriging_result_block)\n&gt; \n&gt; # Dealing with duplicate observations\n&gt; data(meuse)\n&gt; meuse.dup = rbind(meuse, meuse[1,]) # Create duplicate\n&gt; coordinates(meuse.dup) = ~x+y\n&gt; kr = autoKrige(zinc~dist, meuse.dup, meuse.grid)\nWarning in autoKrige(zinc ~ dist, meuse.dup, meuse.grid) :\n  Removed 1 duplicate observation(s) in input_data:\n         coordinates cadmium copper lead zinc  elev       dist   om ffreq soil\n1   (181072, 333611)    11.7     85  299 1022 7.909 0.00135803 13.6     1    1\n139 (181072, 333611)    11.7     85  299 1022 7.909 0.00135803 13.6     1    1\n    lime landuse dist.m\n1      1      Ah     50\n139    1      Ah     50\n[using universal kriging]\n&gt; \n&gt; # Extracting parts from the autoKrige object\n&gt; prediction_spdf = kr$krige_output\n&gt; sample_variogram = kr$exp_var\n&gt; variogram_model = kr$var_model\n&gt; \n&gt; \n&gt; \n&gt; \n&gt; \n&gt; dev.off()\nnull device \n          1 \n&gt;\n<\/pre>\n<p>&nbsp;<\/p>\n<table style=\"color: #000000;\">\n<tbody>\n<tr>\n<td><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_001_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_001_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_002_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_002_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_003_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_003_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_004_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_004_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_005_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/automap\/autoKrige.rd_005_medium.png\" alt=\"\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>autoKrige R Documentation Performs an automatic interpolation Description This function performs automatic kriging on the given dataset. The variogram is generated automatically using autofitVariogram. Usage&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-609","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=609"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/609\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}