我正在研究一个用于编写工作实现的骨架。
我不能在骨架中留下任何未使用的功能。测试实施是否有效。
具体来说 - 如果我测试它,应该只需按下[Run]按钮并查看令人信服的证据证明您的代码有效,原因如下:
a)您的测试显示的分类推理
b)控制台日志中输出的行表示来自那些测试的“通过”
到目前为止,这是我的代码:
kri3 <- function(var, lat, lon, defx, defy){
#making a data frame out of the given vectors
spdf <- data.frame(var,lat,lon)
#makeing spatial point data frame coords
sp::coordinates(spdf) <- ~ lon + lat
bbox <- sp::bbox(spdf)
#variogram stuff
lzn.vgm <- gstat::variogram(var ~ 1, spdf)
lzn.fit1 <- gstat::fit.variogram(lzn.vgm, model = gstat::vgm(1, "Sph", 900, 1))
lzn.fit = automap::autofitVariogram(var ~ 1,
spdf,
model = c("Sph"),
kappa = c(0.05, seq(0.2, 2, 0.1), 5, 10),
fix.values = c(NA, NA, NA),
start_vals = c(NA,NA,NA),
verbose = T)
#making our grid
cs <- c(defx, defy)
bb <- sp::bbox(spdf)
cc <- bb[,1] + (cs/2)
cd <- ceiling(diff(t(bb))/cs)
gold_grd <- sp::GridTopology(cellcentre.offset = cc, cellsize = cs, cells.dim = cd)
gold_grd
p4s <- sp::CRS(sp::proj4string(spdf))
gold_sg <- sp::SpatialGrid(gold_grd, proj4string = p4s)
summary(gold_sg)
#kringing and auto kriging
lzn.kriged <- as.data.frame(gstat::krige(var ~ 1, spdf, gold_sg , model=lzn.fit1))
lzn.Akriged <- automap::autoKrige(var ~ 1, spdf, gold_sg)
lzn.Akriged.pred <- lzn.Akriged$krige_output$var1.pred
lzn.Akriged.var <- lzn.Akriged$krige_output$var1.var
return(lzn.kriged)
return(lzn.Akriged.var)
return(lzn.Akriged.pred)
}
kriw <- kri3(new_river$E_coli, new_river$lat2, new_river$lon2, 0.005, 0.005)
Kmap <- function(lat, lon, kriw){
#making a dataframe for ggplot
kriw <- as.data.frame(kriw)
#making a maps
bbox1 <- ggmap::make_bbox(lon, lat, f = 1.4)
map <- ggmap::get_map(bbox1)
#making a heat map
M1 <- ggmap::ggmap(map) +
ggplot2::geom_tile(data = kriw, ggplot2::aes(x = lon,
y = lat, alpha = var1.pred), fill = "red")
M2 <- ggmap::ggmap(map) +
ggplot2::geom_tile(data = kriw, ggplot2::aes(x = lon,
y = lat, alpha = var1.var), fill = "red")
#Placing both heat maps together
heat <- gridExtra::grid.arrange(M1,M2, ncol=2)
return(heat)
}
Kmap(new_river$lat2, new_river$lon2, kriw)
知道我错过了什么吗?这一切都正确吗?
答案 0 :(得分:1)
您的函数不返回任何值,只需添加如下所示的return语句:
function average(numbers) {
// process array of numbers
return numbers.reduce(function(total, item){
return total + item / numbers.length - 1;
}, 0);
}
function sum(numbers) {
return numbers.reduce(function(total, item){
return total + item;
}, 0);
}