[R] cbind formula definition

Petr PIKAL petr.pikal at precheza.cz
Wed Sep 9 10:40:33 CEST 2009


Hi
r-help-bounces at r-project.org napsal dne 09.09.2009 10:07:49:

> Hi Henrique,
> 
> Thanks for your reply.
> I tried you suggestion but it didn't work with the poLCA package.
> 
> Maybe i didn't express myself good.
> 
> The normal syntax is:
> 
> f <- cbind(V1,V2,V3)~1
> poLCA(f,data)


You complicated it a bit. From poLCA manual it needs a formula
cbind(V1,V2,V3)~1
where V1:V3 are names from data

If you put names of your data frame to variable mena

mena <- names(aktDat)
then you can collect all items into a formula by

f <- as.formula(paste("cbind(", paste(mena, collapse = ","), ")~1"))

and 
poLCA(f,data)

should work.

Regards
Petr


> 
> and what I wanna do is kind of use an expression to automatically 
> generate the "V1,V2,V3" argument of the "cbind expression" via 
> "names(data)"  to assign it to f , so that later the poLCA command uses 
> my "f" expression the same way if I had put in V1,V2,V3 manually.
> 
> Greetings
> Jürgen
> 
> I think the problem is that in cbind need arguments of non character 
> type, seperated by commas
> 
> 
> 
> Henrique Dallazuanna schrieb:
> > I don't understand the cbind(bi) sintax, but you can do this with the 
> > folowing:
> > (Using iris data from R)
> >
> > form <- formula(paste(paste(names(iris), collapse = " + "), "~ 1"))
> >
> > 2009/9/8 "Biedermann, Jürgen" <juergen.biedermann at charite.de 
> > <mailto:juergen.biedermann at charite.de>>
> >
> >     Hi there,
> >
> >     I have the following problem:
> >
> >     I have a package called "polLCA" which has the following syntax:
> >
> >     poLCA(formula, data)
> >
> >     and needs the following formula definition:
> >
> >     formula <- cbind(V1,V2,V3,...)
> >
> >     So far so good.
> >
> >     What I tried now was the following:
> >     #Get "data" with the "read.table" fuction
> >     data <- read.table("d:/ .....)
> >     #Select cols to use in the analysis
> >     aktDat <- data[2:15]
> >     #get the names
> >     names(aktDat)
> >     #put them together in one string, comma as separation sign
> >     bi <- paste(names(aktDat),collapse=",")
> >     #use this string in the "f" function to bind the variables
> >     formula <- cbind(bi)~1
> >     #Calculate the modell
> >     poLCA(formula, data)
> >
> >     but this doesn't work: I get the following error message:
> >
> >     "Warnung in model.matrix.default(formula, mframe) :
> >      variable 'cbind(bi)' converted to a factor"
> >
> >     Could anyone help me?
> >     Thanks
> >
> >     Greetings
> >     Jürgen
> >
> >     ______________________________________________
> >     R-help at r-project.org <mailto:R-help at r-project.org> mailing list
> >     https://stat.ethz.ch/mailman/listinfo/r-help
> >     PLEASE do read the posting guide
> >     http://www.R-project.org/posting-guide.html
> >     and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> >
> > -- 
> > Henrique Dallazuanna
> > Curitiba-Paraná-Brasil
> > 25° 25' 40" S 49° 16' 22" O
> 
> 
> -- 
> Jürgen Biedermann
> Institut für forensische Psychiatrie
> Charite Universitätsmedizin Berlin
> Tel.: 030 8445-1434
> Email: juergen.biedermann at charite.de
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list