0

I am trying to do a lmer model with drop1, in each step with lowest AIC, and remodelling. I learned that LMERConvenienceFunction package can do it. But I am having difficulties with commanding the bfFixefLMER_F.fnc How should I command it?

model:

b <- lmer(metric1~a+b+c+d+e+f+g+h+i+j+k+l+(1|X) + (1|Y), data = dataset)

drop1 (b, test="Chisq")
thor
  • 21,418
  • 31
  • 87
  • 173
borgs
  • 3
  • 5
  • The help page has examples, see `?'LMERConvenienceFunctions'`. As in my comments yesterday, you may prefer `lmerTest::step`. To get more help can you add a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to your question, show what code you have tried, and any errors. thanks – user20650 Mar 31 '17 at 18:43
  • The problem is that when I do the drop1 thing manually I get 3 variables in my model. But when I use : bfFixefLMER_t.fnc I get 2 variables ( I mean I get a different model). I should get same results with the one with manually, don't u think so? – borgs Mar 31 '17 at 21:41
  • no, from looking at the `method` argument of `bfFixefLMER_t.fnc` you see what test is is using to drop variables - the default is to use `t`-test. (imo a bad default) Change to `llrt` or `AIC` / `BIC` and see (read through the help page of `?bfFixefLMER_t.fnc` to make it as comparable as possible). stepwise are much criticised for many reasons: but in practice, using different statistics to drop variables, or using forward compared to backwards, can all return different models. – user20650 Mar 31 '17 at 21:41
  • I tried llrt, AIC and relLik.AIC with both functions (bfFixefLMER_F.fnc AND bfFixefLMER_t.fnc). And I get same results with 2 variables (same model). But when I do it manually I get 3 variables (totally different). It is not logic? – borgs Mar 31 '17 at 21:44
  • The only advice I can give without an example is to make sure your models / tests are as similar as possible ie check all thresholds, check if interactions are getting fitted, RE getting removed, fit by REML etc. As you have not added the code you have used , I cant really say anything more. There are several models in the help pages for lme4 and LMERConvenienceFunctions , so can you choose one , and edit your question to show how you are removing variables with drop1 and then with bfFixefLMER_t.fnc. Then more specific help can be offered. – user20650 Mar 31 '17 at 21:51
  • https://ufile.io/2c86c here is what i do manually and with automated drop1 – borgs Mar 31 '17 at 22:10
  • thanks. from a quick glance. Your drop1 approach removes terms if the removal results in an AIC lower than the null model. bfFixefLMER_t.fnc uses a threshold, set at 5 by default. So skipping to the final model in your doc (it appears you passed the final model produced by your drop1 approach ie with only three variables ; but that;s not important here), the null models aic is -49.412 and with LTKNitrogen removed it is -47.732. As the difference is ~2 , which is less than 5, the variable is removed. So you need to set the threshold, say `threshold = 1e-4`, to only remove if strictly lower. – user20650 Mar 31 '17 at 22:52
  • Voila!!! It works! One more thing, do I have a chance to get p values for final model (for each variable)? – borgs Mar 31 '17 at 23:07
  • 1
    ha., pvalues. Have a read of `?lme4::pvalues` : this is asked and answered a lot!! (I dont think its mentioned in the help but you could refit the model using `nlme::lme` which does give pvalues) But search web for `Harrell stepwise` - these p-values are difficult to interpret due to selection process. (http://stats.stackexchange.com/questions/20836/algorithms-for-automatic-model-selection) – user20650 Mar 31 '17 at 23:11
  • umm my bad. I can get p values by lmerTest package. but I wanted to ask: is there a way to get the p values after automated drop1, for the final model. and also R2 values for the automated final model? I am not lazy but think of hundred metrics and 8 variables... This is the 4th time I am doing all of this modelling thing. So I really dig for doing all of the analysis automatically. – borgs Mar 31 '17 at 23:18
  • To get pvalues automatically, you will need to write a couple of lines of code to grab the terms or model call of the final model, and then get p-values for this choosing which approach you find is most appropriate - you should try to do it. If difficulties ask a new question: but make sure you use provide an reproducible example. lme4 doesnt provide r^2 (the final answer here http://stats.stackexchange.com/questions/111150/calculating-r2-in-mixed-models-using-nakagawa-schielzeths-2013-r2glmm-me but research is done on this :) – user20650 Mar 31 '17 at 23:28
  • 1
    MuMIn provides R2 values :) I am quite sure that you know this. But I just share in case if somebody needs. r.squaredGLMM(model.name) is a very easy way to get R2 values. Writing codes? I think it is beyond my limits for the time being. But who knows? Anyway I am very grateful for your kind helps and patience. Thank you! – borgs Mar 31 '17 at 23:32

0 Answers0