Suppose the dataset, my_data, looks like this
Count | Covariate | offset_a | offset_b |
---|---|---|---|
... | ... | ... | ... |
while using offset_a as my offset, the below statement would work:
glm(my_formula, data = my_data, family = 'quasipoisson', offset = offset_a)
However, if I want to write a loop that passes offset_a and offset_b sequentially into glm(), I wouldn't be able to simply pass a character value into the offset argument. Like this:
offset_list <- c("offset_a", "offset_b")
for (k in offset_list){
...
fit = glm(my_formula, data = my_data, family = 'quasipoisson', offset = k)
...
}
I tried applying noquote() to the offset, as
fit = glm(my_formula, data = my_data, family = 'quasipoisson', offset = noquote(k))
but it doesn't work either.
Does anyone know how to achieve this?
Furtherly,
if we have a character variable,
statement = "glm(my_formula, data = my_data, family = 'quasipoisson', offset = offset_a)"
Is there any way to pass variable, statement, into glm() directly and get the output successfully?
Much Appreciated!