在RMARK中使用Dredge功能

时间:2018-02-11 16:46:12

标签: r

我正在使用RMark来计算巢成功与8个协变量。

我的数据如下:

1) Year
2) Julian Day Egg Lay Date
3) Proportion of Eggs Layed
4) Of eggs Layed, Proportion of Eggs Hatched
5) Mean ibutton Temp Before Hatching
6) Max iButton Temp Before Hatching
7) Mean Te Before Hatching
8) Max Te Before Hatching

Nest Survival Group = 1; 32 2 8 8 0 11 2016 152 1 0.5 30.56 60.5 33.46 71.11;

我正在尝试使用挖泥功能来完成所有可能的组合。

我的代码用于执行单个预测变量与响应变量:

library(RMark)
hatch = scan("C:.../mark file hatch Julian-150forR.inp", what = "character", sep = "\n")  #to find the file
write(sub(";", "", hatch[13:56]), "hatch.txt")
hatch = read.table("hatch.txt")
names(hatch) = c("id", "FirstFound", "LastPresent", "LastChecked", "Fate", "Freq", 
    "Year", "LayDate", "PropLayed", "PropHatch", "MeaniButtn", "MaxiButtn", "MeanTe", 
    "MaxTe")
run.hatch = function() {
    Dot = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~1)))
    Year = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~Year)))
    LayDate = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~LayDate)))
    PropLayed = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~PropLayed)))
    MeaniButtn = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MeaniButtn)))
    MaxiButtn = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MaxiButtn)))
    MeaniTe = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MeanTe)))
    MaxTe = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MaxTe)))
    return(collect.models())
}
hatch.results = run.hatch()

当我尝试使用dredge函数时,这是我的代码:

require(MuMIn)
run.hatch = function() {
    global <- Dot = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~1))) + 
        Year = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~Year))) + 
        LayDate = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~LayDate))) + 
        PropLayed = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~PropLayed))) + 
        MeaniButtn = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MeaniButtn))) + 
        MaxiButtn = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MaxiButtn))) + 
        MeaniTe = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MeanTe))) + 
        MaxTe = mark(hatch, nocc = 58, model = "Nest", model.parameters = list(S = list(formula = ~MaxTe))) + 
        return(collect.models())
}
combinations <- dredge(global)


> Error in nobs(global.model) : object 'global' not found

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您在函数global的范围内定义run.hatch。它外面是看不见的。此外,run.hatch应该返回模型列表,而dredge只需要一个模型。例如:

global <- mark(...)
combinations <- dredge(global)