formal argument "design" matched by multiple actual arguments in cjoint - r

I'm trying out various functions in cjoint package but I encountered errors immediately. When using the package's main function amce(), my R console shows the design argument is matched to multiple actual arguments, but I only supplied one design object from the example data appended under the package.
Not sure if the package has been extensively updated or I may have omitted something. It will be appreciated if someone could shed some insights on this.
# install.packages("cjoint")
# library(cjoint)
data("immigrationconjoint")
data("immigrationdesign")
# Run AMCE estimator using the conjoint design given
results <- amce(Chosen_Immigrant ~ Gender + Education + `Language Skills` + `Country of Origin` + Job + `Job Experience` + `Job Plans` + `Reason for Application` + `Prior Entry`, data=immigrationconjoint, cluster=TRUE, respondent.id="CaseID", design=immigrationdesign)
Error in survey::svyglm(formula, design = svydesign, ...) :
formal argument "design" matched by multiple actual arguments

Related

runMI function error: 'no slot of name "internalList" for this object of class "lavaanList"'

I have run a multiple imputation (m=45, 10 iterations) using MICE and am attempting to fit a series of confirmatory factor analysis and structural equation models on the imputed datasets using the runMI function from semTools. Nearly all of my variables are Likert scales, coded as ordered/ordinal. Here is my code for the first CFA, where mi.res.train is the mice-generated mids object:
ipc_c_model <- '
IPC_C =~ t2IPC6_1 + t2IPC6_2 + t2IPC6_3 + t2IPC6_4 + t2IPC6_5 + t2IPC6_6 + t2IPC6_7'
ipc_c_fit <- runMI(ipc_c_model, mi.res.train, fun = "cfa", ordered = TRUE)
The model does not fit and returns the following error:
Error in slot(value, what) :
no slot of name "internalList" for this object of class "lavaanList"
As far as I can see, the lavaan.mi object that this is supposed to create is a special type of lavaanList object. Any ideas as to what may be causing this error?
Thanks!
Hi all: thanks for this feedback--unfortunately am using a restricted-use dataset so could not share much data without some extra steps. Fortunately, I updated a few packages and the code now appears to be working. I'd tried that previously but apparently missed the lavaan package itself.

Error in rep(" ", spaces1) : invalid 'times' argument

I'm trying to carry out covariate balancing using the ebal package. The basic code is:
W1 <- weightit(Conformidad ~ SexoCon + DurPetFiscPrisión1 +
Edad + HojaHistPen + NacionCon + AnteVivos +
TipoAbog + Reincidencia + Habitualidad + Delitos,
data = Suspension1,
method = "ebal", estimand = "ATT")
I then want to check the balance using the summary function:
summary(W1)
This originally worked fine but now I get the error message:
Error in rep(" ", spaces1) : invalid 'times' argument
It's the same dataset and same code, except I changed some of the covariates. But now even when I go back to original covariates I get the same error. Any ideas would be very appreciated!!
I'm the author of WeightIt. That looks like a bug. I'll take a look at it. Are you using the most updated version of WeightIt?
Also, summary() doesn't assess balance. To do that, you need to use cobalt::bal.tab(). summary() summarizes the distribution of the weights, which is less critical than examining balance. bal.tab() displays the effect sample size as well, which is probably the most important statistic produced by summary().
I encountered the same error message. This happens when the treatment variable is coded as factor or character, but not as numeric in weightit.
To make summary() work, you need to use 1 and 0.

Trying to run this generalised linear model to find the effect on mass of crickets by multiple random effects and I am getting this following error

I am trying to run a glm model to check the variation in the mass of cricket which could be affected by age(numeric), altitude(High or low), temperature(two different temperatures) and the incubators(4 different incubators) they are kept it.
I have tried the glm model which seems to be fine theoretically. The data on excel is all checked as well. I am assuming I have to convert some of the data into binary or some sorts.
glm(crick$Mass ~ crick$Altitude*crick$Age + crick$Altitude*crick$suare(Altitude) + 1/crick$Nymph.ID + 1/crick$Population + crick$Temperature*crick$Altitude + 1/crick$Incubator)
This is the code I am trying to run.
Error in eval(predvars, data, env) : attempt to apply non-function this is the error message.
You need to properly specify the formula (e.g. see examples in ?glm). Try
glm(Mass ~ Altitude*Age + 1/Nymph.ID + 1/Population + Temperature*Altitude + 1/Incubator, data = cricks)
Note that I excluded Altitude*suare(Altitude) which is invalid R syntax for formulas. You'll have to explain more what you're trying to go with here.

Propensity score matching in R (problem with code)

I am a complete beginner at R and don't have much time to complete this analysis.
I need to run propensity score matching. I am using RStudio and have
Uploaded my dataset which is called 'R' and was saved on my desktop
Installed and loaded package Matchit
My dataset has the following headings:
BA (my grouping variable of which someone is either on BA or not, 0=off, 1=on),
Then age, sex, timesincediagnosis, TVS, and tscore which are my matching variables.
I have adapted the following code which I have found online
m.nn <- matchit(ba ~ age + sex + timesincediagnosis + TVS + tscore,
data = R, method= " nearest", ratio = 1)
summary(m.nn)
I am getting the following errors:
Error in summary(m.nn) : object 'm.nn' not found
Error in matchit(ba ~ age + sex + timesincediagnosis + TVS + tscore,
data = R, : nearestnot supported.
I would really appreciate any help with why I am getting the errors or how I can change my code.
Thank you!
Credit goes to #MrFlick for noticing this, but the problem is that " nearest" is not an acceptable value to be passed to method. What you want is "nearest" (without the leading space in the string). (Note that the default method is nearest neighbor matching, so you can omit the method argument entirely if this is what you want to do.)
The error print first (Error in summary(m.nn) : object 'm.nn' not found) occurs because R didn't create the m.nn object because of the other error.

R: finding the source code that produces the output for S4 slot?

G'day Everyone,
When the 'lmer' function in 'lme4' runs its produces an S4 object with a lot of slots. I am interested in one of these slots, namely model#X, and how this 'X' slot output is produced. I want to try reproduce this output for a different model function (glmmPQL) I am using which does not automatically produces this 'X' output (FYI 'lmer' produces an object of class 'mer', and slot 'X' is a model matrix for the fixed effects). Code below shows what I am talking about.
What I want to figure out is how the produced this 'X' data? I looked at the code for 'lmer' by writing it in the terminal without '()' but I couldn't find anything there. I also tried showMethod('lmer') but it says function 'lmer': .
Just wondering if there is a way to get the source code for what the 'X' slot is doing in particular (or any slot in a S4 object)? Or does anyone know how to reproduce this? Thanks lots for your help and time.
library(lme4)
# here is a quick example of what I am looking at using the cake dataset in the 'lme4' package
m <- lmer(cakeglmm<- lmer(angle ~ temp + recipe + (1| replicate), family = gaussian, data = cake)
slotNames(m)
head(m#X)
You started off okay by printing lmer. That won't show you where m#X is set, but you can see which methods are called by lmer.
The methods within lmer can be accessed using lme4:::methodName.
If you look inside lme4:::lmer_finalize, you'll see (paraphrasing):
ans <- new(Class = "mer", ..., X = fr$X, ...)
So that's where the #X slot is being populated. Back up in lmer you'll see that fr comes from lme4:::lmerFrames, and specifically fr$X is calculated by:
X <- if (!is.empty.model(mt))
model.matrix(mt, mf, contrasts)
else matrix(, NROW(Y), 0)

Resources