R中不同效果级别的NLME预测

时间:2018-10-03 20:16:27

标签: r nlme mixed

我有一个田间试验的简单组成示例,该试验有3个位置,每个位置内有4个街区,并向这些田地施用了8种肥料。在这些地块上测量了响应。

这是数据:

#dataframe
loc <- c("Loc1", "Loc2", "Loc3")
block <- c("Block_1", "Block_2", "Block_3", "Block_4")
treat <- as.numeric(c("0","40","80","120","160","200","240","280"))
empty <-expand.grid(treat,  block, loc)
response <- as.numeric(c(7064,  9250,   12306,  13549,  13300,  13973,   
14749,  14086, 7680, 11426, 12874,  12556,  14274,  14289,  15295,  14587, 
8445,   11588,  13223,  13322,  13508,  13616,  13747,  13352, 9454,     
11104,  12462,  13373,  14060,  14576,  14133,  14427, 5463, 8689,  10194,   
11996,  13475, 12544,   12856,  11557, 5251, 7537,  12074,  12438,  12120,   
11312,  9908, 12841, 4643,  7513,   10499,  12423,  12177,  12545,  12876,   
13047, 4992, 9458, 1071,    12104,  13552,  12602,  13210,  14428, 4061, 
3959,   5871,   8016,   9472, 11554,    12525,  12636, 4598, 7717,  7274,    
8476,   9433,   10768,  10275,  8200, 4862, 5727,   6468,   8532,   10662,   
12054,  12227,  12672, 5218, 7878, 8238, 10303, 10331,  13337,  12877,   
11661))
resp.data <- cbind(empty, response)
resp.data <- resp.data[c("Var3", "Var2", "Var1", "response")]
names(resp.data) <- c("loc", "block", "treat", "response")  

我用位置和块作为随机效果调整了指数高原函数。

#exponential plateau function
expfunc <- function(beta0, beta1, beta2, x){
             y <- beta0 * (1 - exp(-exp(beta1) / 1000 * x + beta2))
             return(y)}

# model fit with blocks and locations as random effects
exp.loc_block <- nlme(response ~ expfunc(beta0, beta1, beta2, treat),
                   data = resp.data,
                   fixed = list(beta0 ~ 1, beta1 ~ 1, beta2 ~ 1),
                   random = list(loc = pdDiag(beta0 + beta1 + beta2 ~ 1),
                                 block = pdDiag(beta0 + beta1 + beta2 ~ 1)),
                   start = c(12000, 3, -1),
                   na.action = na.omit,
                   verbose = F)

summary(exp.loc_block)

现在,我希望对0级(固定效果)的响应进行预测。

#prediction at population level (fixed effect)
xvals <- with(resp.data,seq(min(treat),max(treat),length.out=100))
pframe <- data.frame(treat=xvals)
pframe$pred.resp.fix <- predict(exp.loc_block,newdata=pframe,level=0)

到目前为止,它运行良好。他们在区块和位置级别获得了预测。

#prediction at block nested in location level (random effect)
Loc.names.vector <- unique(resp.data$loc)
block.names.vector <- unique(resp.data$block)
pframe2 <- with(resp.data,data.frame(treat=rep(xvals, 12)))
pframe2$loc <- as.factor(rep(Loc.names.vector, each = 400))
pframe2$block <- as.factor(rep(rep(block.names.vector, each = 100), 3))
pframe2$yield.exp <- predict(exp.loc_block,newdata=pframe2)

所以,我的问题是,是否有任何方法可以在位置级别预测响应?

非常感谢任何提示。

谢谢。

0 个答案:

没有答案
相关问题