Skip to content

Adding rows to a table with a loop

3 messages · Weidong Gu, MJS

MJS
#
Hi All,
Its a bit of a beginners question I'm afraid.  
I have a looped stepwise regression (using MASS and StepAIC) to take random
predictors out of the total number.  For this example a random sample of 5
out of a total of 20.  The loop will continue until all combinations of
variables have been run through the loop.  

The output from each loop can be derived from taking the significant (p)
coefficients from the summary command, and coding them '1' (if <0.05) or '0'
(if >0.05), and producing a table of 5 columns for each of the predictors
entered.

The table produced in the loop is much smaller than the input table.  Is
there a way to produce a results table using the original column titles of
the input table which can be matched to the subset predictors table, where
if the variable was not in the subset its row value is 'NA'?

I hope that makes sense.

Cheers In advance,
Matt




--
View this message in context: http://r.789695.n4.nabble.com/Adding-rows-to-a-table-with-a-loop-tp3933634p3933634.html
Sent from the R help mailing list archive at Nabble.com.
#
It surely can be done. One way is to keep track of selected variables
in a set. If a new variable is selected, you expand the selected set
and set the frequency to be one, otherwise just increase the freqency
of the selected variable (if... else).

Also, you might want to have a look at glmulti package which conducts
model selection out of all potential combinations, even including
interactions if you don't have many variables.

HTH

Weidong Gu
On Mon, Oct 24, 2011 at 11:58 AM, MJS <taranis.1986 at gmail.com> wrote:
1 day later
MJS
#
Thanks for the response, and the advice, glmulti looks like it could be quite
a good alternative.

As for the adding to the results table problem from within the loop, this
webpage:
<http://ryouready.wordpress.com/2009/01/23/r-combining-vectors-or-data-frames-of-unequal-length-into-one-data-frame/>
answered a number of my questions.

--
View this message in context: http://r.789695.n4.nabble.com/Adding-rows-to-a-table-with-a-loop-tp3933634p3940293.html
Sent from the R help mailing list archive at Nabble.com.