miceadds icon indicating copy to clipboard operation
miceadds copied to clipboard

glm.cluster reliant on/generates NULL wgt__ value

Open tsrobinson opened this issue 4 years ago • 3 comments

I have glm.cluster embedded in a larger function. When I run the function (see below) in a new R session, I get the following error: Error in eval(extras, data, env) : object 'wgt_' not found

When I run glm.cluster(...) with the parameters saved as variables but without assigning the output, it automatically saves wgt__ as a value in the session environment. This does not return an error and I can then run the overarching function without errors.

It seems to hinge on whether or not wgt__ is saved in the environment - as soon as I remove this from the environment, the error message returns. I can also run the function in a new session by assigning wgt__ <- NULL before the function call.

I've included example code and some fake data which generates the error.

R Version: 3.6.0 Mac OSX 10.14.5

Minimal working example

`library(tidyverse) library(miceadds)

example_data <- read_csv("example_data.csv")

cluster_glm <- function(data, formula, cluster, type) {

mod <- glm.cluster(formula = formula, data = data, cluster = cluster, weights = NULL, family = if(type == "logit") { binomial(link="logit") } else { gaussian } ) %>% summary(.) %>% as.data.frame(.)

return(mod) }

mod_basic_vote <- cluster_glm(formula = "Y ~ X1 + X2 + X3", data = example_data, type = "logit", cluster = "pid")

wgt__ <- NULL

mod_basic_vote <- cluster_glm(formula = "Y ~ X1 + X2 + X3", data = example_data, type = "logit", cluster = "pid")` mwe.zip

tsrobinson avatar Aug 02 '19 21:08 tsrobinson