-
Notifications
You must be signed in to change notification settings - Fork 7
/
Variogram Modelling.rsx
34 lines (30 loc) · 1.01 KB
/
Variogram Modelling.rsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
##[R-Geostatistics]=group
##showplots
##layer=vector
##field=field layer
##Estimate_range_and_psill_initial_values_from_sample_variogram=boolean True
##nugget=number 0
##model=selection Exp;Sph;Gau;Mat
##range=number 0
##psill=number 0
##Show_Sum_of_Square_Errors=boolean False
library('sp')
library('gstat')
print(model)
Models<-c("Exp","Sph","Gau","Mat")
model2<-Models[model+1]
# adjust variogram
names(layer)[names(layer)==field]="field"
layer$field <- as.numeric(as.character(layer$field))
str(layer)
layer <- remove.duplicates(layer)
layer <- layer[!is.na(layer$field),]
g <- gstat(id = field, formula = field~1, data = layer)
vg <- variogram(g)
if(Estimate_range_and_psill_initial_values_from_sample_variogram){range=NA}
if(Estimate_range_and_psill_initial_values_from_sample_variogram){psill=NA}
vgm <- vgm(nugget=nugget, range=range, psill=psill, model=model2)
vgm = fit.variogram(vg, vgm)
>vgm
>if(Show_Sum_of_Square_Errors==TRUE){paste("SSE:", attr(vgm, "SSErr"))}
plot(vg, vgm, main = title , plot.numbers = TRUE)