Error when running MCP library - 'rlang_is_formula' - r

I'm trying to run a model with the mcp package. Here is what I'm running:
model <- list(
response ~ 1,
~ 0 + time,
~ 0 + time)
fit <- mcp(model, data=df)
This gives the error: Error in is.type(x) : object 'rlang_is_formula' not found
I've tried removing and reinstalling the rlang package, with no luck. I'm using R-4.1.2, and rlang is version 1.0.4. mcp package is version 0.3.1.
Any ideas how to solve this issue?

Detaching other problematic packages and reloading everything did not work. The issue was resolved after reinstalling the mcp package completely.

Related

Issue with GLMM in glmmTMB

I am trying to run the following model:
MP1 <- glmmTMB(Abundance ~ All_predator + Year + Location + Depth +
(1 | Site/Site.Transect),
data = plandat,
family = "poisson")
but am getting this error:
Error in .Call("getParameterOrder", data, parameters, new.env(),
PACKAGE = DLL) :
Incorrect number of arguments (3), expecting 4 for
'getParameterOrder'
Does anyone know what this issue might be?
This is a binary-incompatibility problem as documented here. You should probably have seen a "Package version inconsistency detected" message telling you to re-install glmmTMB from source. Depending on the release sequence of TMB and glmmTMB on CRAN, updating from CRAN as usual might work; otherwise you need to re-install from source (see ?glmmTMB::reinstalling).

Error "unused argument (env = environment(f)" in lme4

I am trying to perform an lmer in R, from the lme4 package, but I keep getting the error :
Error in reformulate(paste0("(", vapply(findbars(f), deparse1, ""), ")"), :
unused argument (env = environment(f))".
Any ideas? Example with iris:
library(lme4)
lmer(iris$Sepal.Length ~ iris$Sepal.Width + (1|iris$Species))
(I know this doesn't make much sense intuitively, but as an example)
This is a bug/incompatibility between the current (CRAN) version of lme4, 1.1-28, and versions of R older than 3.6.0. From the r-sig-mixed-models mailing list:
This is a bug that was recently noted (and fixed in the development
version) here:
https://github.com/lme4/lme4/issues/664
Running this code snippet
assign('reformulate', envir = topenv(),
function(..., env = parent.env) {
f <- base::reformulate(...)
environment(f) <- env
return(f)
})
might fix the problem.
Alternately, if you have development tools (compilers etc.) installed on your computer, remotes::install_github("lme4/lme4") will install the development version (which should also fix the problem).
Or you can install a more recent version of R (which might be the best solution and save you future headaches) — see instructions here for installing an up-to-date version of R on Ubuntu.

Zero-Inflation NB - object 'model_count' not found

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.

Computation failed in `stat_smooth()`: object 'C_crspl' not found

I am trying to add a geom_smooth() to a qplot() with the following code:
library(ggplot2)
library(ggplot2movies)
qplot(votes, rating, data = movies) + geom_smooth()
However, the smoother is missing from the plot. I also receive the following warning message:
Computation failed in stat_smooth(): object 'C_crspl' not found
Does anybody know what is wrong here?
This is my setup:
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS
I had similar issues:
# `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
# Warning message:
# Computation failed in `stat_smooth()`:
# object 'C_crspl' not found
and
# Warning message:
# Computation failed in `stat_smooth()`:
# object 'C_magic' not found
when using geom_smooth(method="gam"). The problems vanished when I explicitly loaded the mgcv package version 1.8-17. I guess by default, ggplot (I use 2.2.1.9000) looked at 1.8-16, which was also in the search path. So you might want to update mgcv or make sure that the latest version is used.
I could not reproduce your problem: it works fine in my system. I guess you have a problem with some ggplot2 dependency. Try restarting your session and reinstall ggplot2.
If that doesn't work, test geom_smooth() with a different dataset and a different method, e.g. qplot(Sepal.Length, Sepal.Width, data = iris) + geom_smooth(method = 'lm')
I had the same exact issue. Tried loading mgcv explicitly and this did nothing. Since I originally relied on ggplot2 to install mgcv, I went back and installed mgcv myself so that the newest version was included and then re-installed ggplot2 and the issue went away. This is on Ubuntu 16.04 with ggplot2 2_2.2.1 and mgcv 1.8-23.
I also had this problem and almost gave up. However, when I simply reinstalled mgcv before and ggplot2 later, the script simply went back to working as before.

Are there known compatibility issues with R package mgcv? Are there general rules for compatibility?

I use R version 2.15.1 (2012-06-22) and mgcv version 1.7-22
I load the following set of packages in R:
library(sqldf)
library(timeDate)
library(forecast)
library(xts)
library(tseries)
library(MASS)
library(mgcv)
It happens that I can not run a simple model (I omit the code). Even the sample code taken from the help pages:
dat = gamSim(1,n=400,dist="normal",scale=2)
b = gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)
gives an error:
Error in qr.qty(qrc, sm$S[[l]]) :
NA/NaN/Inf in foreign function call (arg 5)
In addition: Warning message:
In smoothCon(split$smooth.spec[[i]], data, knots, absorb.cons, scale.penalty = scale.penalty, :
number of items to replace is not a multiple of replacement length
Note that everything works fine, if I just load the package mgcv and then use the sample code right away. It also works if I just load all the packages and run the sample code. It just does not work if I
load all packages
do some file reading, sqldf statements, ts operations and some models from package forecast.
if I then apply GAM, it does not work anymore.
Apparently the variable definitions in the general environment mess up the functioning of the package.
Are there any known issues? Are there general rules that I have to obey if I load various packages? Can I write code that "disturbed" the package mgcv?
# Richard there are 2 GAM related packages: gam and mgcv. Loading both libraries at the same time usually causes a conflict.
Loading mgcv as the first package solved my problem ... strange but true.

Resources