Hi, I'd like to apply a 2^k factorial design with k=10 parameters. Obviously this results in a quite long term for the model equation due to the high number of combinations of parameters. How can I specify the equation for the linear model (lm) without writing all combinations explicitly down by hand? Does a R command exist for this problematic? Thanks for your help in advance, Sven
Hi Sven, just use: lm(y~(x1+x2+x3+...+x10)^10) e.g., y <- rnorm(5000) x1 <- factor(sample(0:1, 5000, TRUE)) x2 <- factor(sample(0:1, 5000, TRUE)) x3 <- factor(sample(0:1, 5000, TRUE)) x4 <- factor(sample(0:1, 5000, TRUE)) lm1 <- lm(y~(x1+x2+x3+x4)^4) summary(lm1) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Sven" <svuwie at gmx.de> To: <r-help at stat.math.ethz.ch> Sent: Tuesday, November 30, 2004 12:59 PM Subject: [R] 2k-factorial design with 10 parameters> Hi, > > I'd like to apply a 2^k factorial design with k=10 parameters. > Obviously this results in a quite long term for the model equation > due to the high number of combinations of parameters. > > How can I specify the equation for the linear model (lm) without > writing all combinations explicitly down by hand? Does a R command > exist for this problematic? > > Thanks for your help in advance, > Sven > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
On Tue, 30 Nov 2004, Sven wrote:> I'd like to apply a 2^k factorial design with k=10 parameters. Obviously this > results in a quite long term for the model equation due to the high number of > combinations of parameters. > > How can I specify the equation for the linear model (lm) without writing all > combinations explicitly down by hand? Does a R command exist for this > problematic?I assume you mean k=10 factors (there are a lot more parameters). aov(y ~ .^10, data=mydata) will do what you are probably asking, if you have a data frame with response y and the ten factors. I'm not sure how you could analyse the 1000 odd lines of output, so reduce 10 to something sensible (like 2 or 3) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On 30 Nov 2004 at 12:59, Sven wrote:> Hi, > > I'd like to apply a 2^k factorial design with k=10 parameters. > Obviously this results in a quite long term for the model equation due > to the high number of combinations of parameters. > > How can I specify the equation for the linear model (lm) without > writing all combinations explicitly down by hand? Does a R command > exist for this problematic?Hi Sven from ?lm The specification 'first*second' indicates the _cross_ of 'first' and 'second'. This is the same as 'first + second + first:second' and from ?formula ## Create a formula for a model with a large number of variables: xnam <- paste("x", 1:25, sep="") (fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+")))) If you change 1:25 to 1:10 and collapse to * and use fmla in your model you will get what you want (I suppose). But I woder if it has any sense. Cheers Petr> > Thanks for your help in advance, > Sven > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz