I frequently used extracted marginal and conditional R^2 from mixed models using r.rsquaredGLMM(mod) from package MuMIn. Since today this doesn't work any more and I get the following error:
Error in r.rsquaredGLMM(mod) : could not find function "r.rsquaredGLMM"
Does anyone have a solution for this issue?
Thanks, Katharina
Below a code example:
library(MuMIn)
mod <- lmer(Reaction~Subject + (1|Days), data=sleepstudy)
r.rsquaredGLMM(mod)
```
Related
I have an R script that has worked fine up until today, but now I cannot run any lme4 models. If, for example, I try to run the model from the lme4 example data:
library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
I get the following error:
Error in .empty.factors(e1) : object 'R_empty_factors' not found
This happens for any lme4 model that I try to fit. The package loads fine. I've also tried re-installing lme4, but this didn't solve it. Other packages in R seem to work fine (e.g., dplyr)
I've also tried Googling this particular error and haven't found anything. Any ideas how to resolve this?
I am modeling a mediated zero-inflated negative binomial (ZINB) model. i am following the steps of O'Rourke & Vazquez (2019) --> https://www.sciencedirect.com/science/article/abs/pii/S0306460319301078
A few days ago i was running a different ZINB model which ran perfectly fine. However, today i wrote a different model, same variables, but somehow it doesn't run anymore and gives a strange error. When i try my previous model i suddenly get the same error, namely:
Error in zeroinfl(Y1 ~ X1 + M1 | X1 + : object 'model_count' not found
The rest of my code:
#loading required packages
library(psych)
library(foreign)
library(ggplot2)
library(MASS)
library(pscl)
library(nonnest2)
library(lmtest)
library(boot)
#Import data
mydata
#Fit a ZINB model
ex1zinb <- zeroinfl(X1 ~ Y1 + M1 | Y1 + M1, data = mydata, dist="negbin", EM= TRUE)
I already checked the assumption for the statistical analyses etc., and it is especially strange that a similar model did run a few days ago and not anymore. I did try to install several packages today but i ran into a non-zero exit status. Following some comments on stackoverflow i installed a package by adding dependencies = TRUE, but it ran stuck. Afterwards the problems started. Maybe there is something wrong with my packages?
When loading the libraries i get the following messages:
> library(psych)
> library(foreign)
> library(ggplot2)
Need help? Try Stackoverflow: https://stackoverflow.com/tags/ggplot2
Attaching package: ‘ggplot2’
The following objects are masked from ‘package:psych’:
%+%, alpha
> library(MASS)
> library(pscl)
Classes and Methods for R developed in the
Political Science Computational Laboratory
Department of Political Science
Stanford University
Simon Jackman
hurdle and zeroinfl functions by Achim Zeileis
> library(nonnest2)
This is nonnest2 0.5-3.
nonnest2 has not been tested with all combinations of model classes.
> library(lmtest)
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
> library(boot)
Attaching package: ‘boot’
The following object is masked from ‘package:psych’:
logit
Anyone some suggestions/insights?
Thanks in advance!
Edit: i do get a normal output when running a non-zero inflated negative binomial model. The following code runs smooth:
summary(ex1nb <- glm.nb(Y1~ X1 + M1, data = mydata))
So i think my data is fine?
I got that error too. I used R 4.0 then tried R 3.6. No luck.
I was able to get the error to go away when I removed the EM = TRUE parameter.
I'm not sure if this helps.
Author of the paper here (O'Rourke) - this was due to a pscl package update where they changed the location of the EM statement. We have updated the code for the paper removing the "EM=TRUE" statements from each relevant section and are in the process of getting it on github so we can flexibly update in accordance with any other package changes. Please feel free to reach out if you have other issues with the code.
I rarely use R, but need for a helper function that somebody has given me. I have the following line:
league_model_19 <- gam(SHOT_MADE_FLAG ~ ti(LOC_X) + ti(LOC_Y) + ti(LOC_X, LOC_Y), data = shots)
But, when I run it, the following error message is displayed:
Error in ti.default(LOC_X) :
'tif' and 'freq' cannot both be NULL if 'x' is not a ti
I saw online somebody write code along the lines of:
if(is.null(tif)){
if(is.null(freq))
stop("'tif' and 'freq' cannot both be NULL if 'x' is not a ti")
else tif <- freq2tif(freq)
}
But I don't know how to integrate this into my current line, or if there is a more efficient way to do this. Does anybody know how to get rid of this error message so I can proceed with my code? Let me know if more details are needed.
Edit: Added minimal dataframe to reproduce error (player_id and player_name aren't used here, just left in there). This is the data that is in 'shots' as called in the line of code I shared:
PLAYER_ID,PLAYER_NAME,LOC_X,LOC_Y,SHOT_MADE_FLAG
1627759,Jaylen Brown,-20,19,0
1627759,Jaylen Brown,-29,168,1
1627759,Jaylen Brown,7,30,1
1627759,Jaylen Brown,9,6,0
1627759,Jaylen Brown,-176,186,0
Sounds like you either don't have the mgcv package loaded, or you have the tis package loaded after mgcv and the former is masking the latter.
If you didn't load mgcv, add library('mgcv') to your script before fitting the gam().
If you have mgcv loaded but also loaded the tis package, both packages provide a ti() function and it seems the tis one is being found first on the search path. Your best option is to use the fully qualified name for the ti() so that you inform R as to which ti() you want to use.
Try:
league_model_19 <- gam(SHOT_MADE_FLAG ~ mgcv::ti(LOC_X) +
mgcv::ti(LOC_Y) +
mgcv::ti(LOC_X, LOC_Y),
data = shots)
You could also change the script to load mgcv after tis but this might cause later problems when you use the ti() from the tis package; in which case you could use tis:ti() in those places.
I'm trying to predict values with a linear mixed model and new data, but I keep getting errors that both functions I'm trying (predict.lme from nlme, and predict.merMod from lme4) do not exist. The packages are installed and loaded.
I first tried using predict.lme (nlme). I note that I've installed and loaded the package, since obviously this is a reason the function may not be found.
But I get this error:
Error in predict.lme(object = PlotModel.best, newdata = PlotInvData_predict,:
could not find function "predict.lme"
I've had random problems with nlme before, so I decide to try predict.merMod (lme4), but I get the same error that that function can't be found. I thought maybe those functions can't handle the interval argument that the regular predict function can. I get rid of that, and it still doesn't work. I tested other functions in those packages, and they work just fine. So something is wrong with my workflow, but I can't figure out what. It's the same workflow as with the regular predict function, which I've used just fine.
What am I doing wrong?
Here's the new data:
PlotInvData_predict <- read.csv(file="D:/ThesisPart2/Data/PlotInvData_predict.csv", header=TRUE, sep=",")
Heres the model:
PlotModel.best <- lmer(d_InvCov ~ TimeSinceDist + UnitArea_ha + (1|MgmtSame)+ (1|LandMgmt.1), PlotInvData)
Then I first tried using predict.lme (nlme). I note that I've installed and loaded the package, since obviously this is a reason the function may not be found.
install.packages("nlme")
library(nlme)
p_bd <- predict.lme(object=PlotModel.best, newdata=PlotInvData_predict, interval="confidence")
Here's the error, again:
Error in predict.lme(object = PlotModel.best, newdata = PlotInvData_predict, :
could not find function "predict.lme"
When using the regular predict function with a different model (linear model), I would get something like this as a result:
fit lwr upr
1 1.098959 0.5803632 1.617556
2 1.156005 0.6627035 1.649306
3 1.213050 0.7408797 1.685220
4 1.270095 0.8143122 1.725879
5 1.327141 0.8824762 1.771805
6 1.384186 0.9449715 1.823401
7 1.441231 1.0015871 1.880875
I'm using h2o package and trying to create a learner using the below given code
install.packages("h2o")
library("h2o")
h2o.learner <- makeLearner("regr.h2o.deeplearning",predict.type = "response")
But I'm getting this error
> h2o.learner <- makeLearner("regr.h2o.deeplearning",predict.type = "response")
Error: could not find function "makeLearner"
Note: Few months back I used this code without any problem.
Any idea what could be possible thing for this error?
The correct code for this is simply
library(mlr)
h2o.learner = makeLearner("regr.h2o.deeplearning")
The makeLearner() is not part of H2O. It appears to be part of the mlr package. It also seems that mlr does have h2o support, so it might be as simple as adding a library(mlr) to the top of your script? (Making sure that the mlr package has been installed, already, of course.)