Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anova.merMod error with find_best_model.lmerModLmerTest #83

Open
HugoNjb opened this issue Aug 27, 2018 · 2 comments
Open

anova.merMod error with find_best_model.lmerModLmerTest #83

HugoNjb opened this issue Aug 27, 2018 · 2 comments

Comments

@HugoNjb
Copy link
Contributor

HugoNjb commented Aug 27, 2018

1

When NA values are in a dataset, using the find_best_model function returns the following error:

data <- affective
fit <- lmer(Tolerating ~ Salary + Life_Satisfaction + Concealing + (1|Sex) + (1|Age), data=data)
best <- find_best_model(fit)

Error in anova.merMod(new("lmerModLmerTest", vcov_varpar = c(0.0686147429065321, :
models were not all fitted to the same size of dataset

Solution
Removing NA values only for the variables used in the formula

  # Recreating the dataset without NA
  dataComplete <- get_all_vars(fit)[complete.cases(get_all_vars(fit)), ]

  # fit models
  models <- c()
  for (formula in combinations) {
    newfit <- update(fit, formula, data = dataComplete)
    models <- c(models, newfit)
  }

2

Using the same function, warning messages are always displayed:

data <- affective
fit <- lmer(Tolerating ~ Salary + Life_Satisfaction + Concealing + (1|Sex) + (1|Age), data=data)
best <- find_best_model(fit)

Warning message:
In anova.merMod(new("lmerModLmerTest", vcov_varpar = c(0.0686147429065321, :
failed to find model names, assigning generic names

Solution
Hiding warnings when the anova are computed.

  # No warnings for this part
  options(warn = -1)
  
  # Model comparison
  comparison <- as.data.frame(do.call("anova", models))
  comparison$formula <- combinations

  # Re-displaying warning messages
  options(warn = 0)
@DominiqueMakowski
Copy link
Member

nice solving :)

HugoNjb added a commit to HugoNjb/psycho.R that referenced this issue Aug 27, 2018
@HugoNjb
Copy link
Contributor Author

HugoNjb commented Aug 27, 2018

Thank you !

HugoNjb added a commit to HugoNjb/psycho.R that referenced this issue Aug 28, 2018
Avoid having to attach the dataset.

Error in eval(inp, data, env) : object 'Tolerating' not found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants