Reputation: 1
I'm using RMark to calculate nest success vs. 8 covariates.
My data looks like:
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 ;
I'm trying to use the dredge function to do all possible combinations.
My code to do single predictor vs. response varable:
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()
When I try to use the dredge
function, here's my code:
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
Any suggestions?
Upvotes: 0
Views: 231
Reputation: 1562
You define global
within the scope of function run.hatch
. It is invisible outside of it. Besides, run.hatch
is supposed to return a list of models, while dredge
expects just one model. For example:
global <- mark(...)
combinations <- dredge(global)
Upvotes: 1