0

loess用来在各个图的测量日期之间插入数据。我想获得每年所有 48 个地块的每日分辨率。以下是我的数据集中的一个示例:

dput(vi.sample)

结构(list = C(2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L,2012L 2012L), 朱利安 = c(150L, 153L, 157L, 165L, 173L, 179L, 186L, 193L, 201L, 208L, 226L, 150L, 153L, 157L, 165L, 173L, 179L, 186L, 1908L, 226L, 22, ), jdx = c(2.573770492, 2.625245902, 2.693879781, 2.831147541, 2.968415301, 3.07136612, 3.19147541, 3.311584699, 3.448852459, 3.568961749, 3.877814208, 2.573770492, 2.625245902, 2.693879781, 2.831147541, 2.968415301, 3.07136612, 3.19147541, 3.311584699, 3.448852459, 3.568961749, 3.877814208) , 站点 = 结构 (c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), .Label = "east", class = "factor"), type = structure(c(1L, 1L, 1L, 1L, 1L,1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "b", class = "factor"), trt =结构(c(1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L), .Label = "a", class = "factor"), plot = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), vi = c(0.41, 0.44, 0.52, 0.64, 0.66, 0.67, 0.64, 0.66, 0.61, 0.7, 0.7, 0.41, 0.45, 0.55, 0.61, 0.63, 0.6 , 0.63, 0.64, 0.6, 0.7, 0.69)), .Names = c("year", "julian", "jdx", "site", "type", "trt", "plot", "vi") , class = "data.frame", row.names = c(NA, -22L))b", class = "factor"), trt = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "a", class = "factor"), plot = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L , 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), vi = c(0.41, 0.44, 0.52, 0.64, 0.66, 0.67, 0.64, 0.66, 0.61, 0.7, 0.7, 0.41, 0.45, 0.55, 0.61, 0.63, 0.66, 0.63, 0.64, 0.6, 0.7, 0.69)), .Names = c("year", "julian", "jdx", "site", "type", " trt"、"plot"、"vi")、class = "data.frame"、row.names = c(NA, -22L))b", class = "factor"), trt = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "a", class = "factor"), plot = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L , 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), vi = c(0.41, 0.44, 0.52, 0.64, 0.66, 0.67, 0.64, 0.66, 0.61, 0.7, 0.7, 0.41, 0.45, 0.55, 0.61, 0.63, 0.66, 0.63, 0.64, 0.6, 0.7, 0.69)), .Names = c("year", "julian", "jdx", "site", "type", " trt"、"plot"、"vi")、class = "data.frame"、row.names = c(NA, -22L))类=“因子”),绘图= c(1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L , 2L, 2L), vi = c(0.41, 0.44, 0.52, 0.64, 0.66, 0.67, 0.64, 0.66, 0.61, 0.7, 0.7, 0.41, 0.45, 0.55, 0.61, 0.63, 0.66, 0.63, 0.64, 0.63, 0.64, 0.7, 0.69)), .Names = c("year", "julian", "jdx", "site", "type", "trt", "plot", "vi"), class = "data.frame ", row.names = c(NA, -22L))类=“因子”),绘图= c(1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L , 2L, 2L), vi = c(0.41, 0.44, 0.52, 0.64, 0.66, 0.67, 0.64, 0.66, 0.61, 0.7, 0.7, 0.41, 0.45, 0.55, 0.61, 0.63, 0.66, 0.63, 0.64, 0.63, 0.64, 0.7, 0.69)), .Names = c("year", "julian", "jdx", "site", "type", "trt", "plot", "vi"), class = "data.frame ", row.names = c(NA, -22L))“类型”、“trt”、“绘图”、“vi”)、class = “data.frame”、row.names = c(NA, -22L))“类型”、“trt”、“绘图”、“vi”)、class = “data.frame”、row.names = c(NA, -22L))

我需要在收集的数据的三个季节(2012 - 2014 年)的每一季中插入每个地块的数据。subset我已经通过使用该功能成功地做到了这一点。请注意,我使用的是朱利安日期,但我并不特别喜欢这种日期格式。

lo <- loess(vi~julian, 
               subset(vi.sample, year=="2012" & site=="east" 
               & type=="b" & trt=="a" & plot=="1"),
               model=TRUE,
               na.action=na.exclude)

问题:有没有一种方法可以自动化代码来插入来自每个情节/年份组合的数据,而不必对每个情节/年份组合进行子集化?我正在考虑nlsList使用| year/site/type/trt/plot设计的功能。

我的第二个问题涉及predict功能。以下代码成功显示了上面指定图的拟合 vi 值。

pred <- predict(lo, seq(from =150, to =226, 
            by = 1), se=FALSE)

但是,相应的 x 值与原始儒略日期不同。
问题:如何获得预测值来表示黄土模型中使用的儒略日期?请注意,这些日期可能因每年/情节而异。

4

1 回答 1

1

对于问题 1,这是一个标准的数据操作 - 拆分、应用、组合。在这里使用plyr

library(plyr)
fits <- dlply(vi.sample, .(year, site, type, trt, plot), .fun=function(samp)
    loess(vi ~ julian, model=T, na.action=na.exclude, data=samp))

您按年份/站点/类型/trt/plot 将数据分组,应用 loess 函数,然后将结果组合回列表中。

对于第二个问题,您在进行预测时选择了朱利安日期,也许我在那里遗漏了一些东西。

于 2015-07-27T20:27:28.673 回答