1

我正在使用包fields进行空间分析。

我的数据集如下:

               x     y
Kopenhagen  12,57 55,68
Rotterdam    4,48 51,92
Belgrade    20,46 44,82
Budapest    19,04  47,5
Dublin      -6,27 53,34
Rome        12,48 41,89
Lisbon      -9,14 38,71
Bucharest    26,1 44,45
Madrid       -3,7 40,42
Lausanne     6,63 46,52
London      -0,13  51,5
Kiel        10,13 54,33
Augsburg    10,89 48,36
Innsbruck  11,398 47,25
Helsinki    24,94 60,17
Lyon         4,83 45,77
Ngreece      22,5  41,5
Ancona      13,11 43,37
Forde         5,9 61,44
Warsawa     21,01 52,23
Uppsala     17,64 59,86
Barcelona    2,17 41,38
Prague      14,42 50,09

这是的输出

dput(map)

structure(list(x = structure(c(6L, 18L, 11L, 10L, 21L, 5L, 23L, 
16L, 17L, 22L, 1L, 2L, 3L, 4L, 15L, 19L, 14L, 7L, 20L, 12L, 9L, 
13L, 8L), .Label = c("-0,13", "10,13", "10,89", "11,398", "12,48", 
"12,57", "13,11", "14,42", "17,64", "19,04", "20,46", "21,01", 
"2,17", "22,5", "24,94", "26,1", "-3,7", "4,48", "4,83", "5,9", 
"-6,27", "6,63", "-9,14"), class = "factor"), y = structure(c(20L, 
16L, 8L, 12L, 18L, 5L, 1L, 7L, 2L, 10L, 15L, 19L, 13L, 11L, 22L, 
9L, 4L, 6L, 23L, 17L, 21L, 3L, 14L), .Label = c("38,71", "40,42", 
"41,38", "41,5", "41,89", "43,37", "44,45", "44,82", "45,77", 
"46,52", "47,25", "47,5", "48,36", "50,09", "51,5", "51,92", 
"52,23", "53,34", "54,33", "55,68", "59,86", "60,17", "61,44"
), class = "factor")), .Names = c("x", "y"), class = "data.frame", row.names=                           
c("Kopenhagen","Rotterdam", "Belgrade", "Budapest", "Dublin", "Rome", "Lisbon", 
"Bucharest", "Madrid", "Lausanne", "London", "Kiel", "Augsburg", 
"Innsbruck", "Helsinki", "Lyon", "Ngreece", "Ancona", "Forde", 
"Warsawa", "Uppsala", "Barcelona", "Prague"))

[1]  97.11559  59.86429  25.85145  54.56235  86.00903  17.45889  81.48449
[8]  87.57361  68.49520  44.40894 106.80953  67.36760  77.33586  47.96955
[15]  35.00993  75.26571  43.15965  17.55405  65.85301  46.19634 126.52848
[22]  42.26424  53.29187

第一个数据集称为map,第二个称为sigma

我写了这段代码:

fit<-Krig(map, sigma, theta=100)

但它给了我以下错误:

Error in signif(mat, digits) : 
  Non-numeric argument to mathematical function

我不明白我错在哪里,因为我的数据集的组织看起来与字段包手册中的相同。

非常感谢任何帮助。

4

1 回答 1

0

错误是因为您的 x 和 y 列是因素。您必须将一个因子转换为近似其原始数值。

 map$x <- as.numeric(gsub(",",".", map$x))
 map$y <- as.numeric(gsub(",",".", map$y))
Krig(map, sigma, theta=100)
Call:
Krig(x = dat2, Y = sigma, theta = 100)

 Number of Observations:                23    
 Number of parameters in the null space 3     
 Parameters for fixed spatial drift     3     
 Model degrees of freedom:              19.2  
 Residual degrees of freedom:           3.8   
 GCV estimate for sigma:                9.943 
 MLE for sigma:                         8.931 
 MLE for rho:                           8808  
 lambda                                 0.0091
 User rho                               NA    
 User sigma^2                           NA    

我不知道您是如何阅读地图结构的,但是如果您将其作为数字阅读,则可以轻松避免转换。例如 :

map <- read.table(files,sep=',')
于 2013-01-03T15:30:17.890 回答