Skip to content

poLCA problem

2 messages · Scott Colwell, Rasmus Liland

#
Good morning everyone,

I am running into errors with poLCA as follows:

Error in round(mf) : non-numeric argument to mathematical function.

Here is what I have. Both variables are coded as 1, 2, 3

df <- as.data.frame(data)

items <- c("x1", "x2")  <- there are more variables but shortened for this
purpose

df2 <- df[items]

i <- cbind(x1, x2)~1

poLCA (i, df2, nclass=2, maxiter=100, nrep=10, verbose =TRUE)

It is after the poLCA that I get the error. Any thoughts on what is causing
this?

Thanks,

Scott
4 days later
#
Dear Scott,

I think the issue here is you need to 
form a correct formula poLCA::poLCA can 
accept.

The help page ?poLCA::election has this 
example:

	# Latent class models with one (loglinear independence) to three classes
	data(election)
	f <- cbind(MORALG,CARESG,KNOWG,LEADG,DISHONG,INTELG,
	           MORALB,CARESB,KNOWB,LEADB,DISHONB,INTELB)~1
	nes1 <- poLCA(f,election,nclass=1)  # log-likelihood: -18647.31
	nes2 <- poLCA(f,election,nclass=2)  # log-likelihood: -17344.92
	nes3 <- poLCA(f,election,nclass=3)  # log-likelihood: -16714.66

Perhaps if you export df first using 
data() and try to use cbind(x1, x2)~1 as 
the formula ... 

	data(df2)
	f <- cbind(x1, x2)~1
	poLCA(f, df2, nclass=2, maxiter=100, nrep=10, verbose =TRUE)

Best,
Rasmus

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20210309/6d3664f7/attachment.sig>