0

I am regressing a gene on another gene subset. Then I use stepAIC to reduce the number of explanatory genes. How do I get the index of the NON-omitted variables, so that I could analyse them?

gene_subset=c(y=genes[,i], genes[,other_genes]);
reduced_model=stepAIC(y~.,data=gene_subset,trace=false);
sachinruk
  • 9,571
  • 12
  • 55
  • 86
  • Please provide [some example data](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), and your expected output. What does "the index" refer to? – Henrik Aug 26 '13 at 08:15

1 Answers1

1

Here is one solution that I got from r-help mail list, any other more efficient ways would be welcome.

# create example data frame
y <- rnorm(30)
gene_subset <- data.frame(y, x1=rnorm(30), x2=rnorm(30), x3=100*y+rnorm(30))

# fit a full linear model
fit <- lm(y ~ ., df)

# reduce the model
reduced_model <- stepAIC(fit, trace=FALSE)

# NON-omitted variables (excluding the response)
keepx <- names(reduced_model$model)[-1]
index <- match(keepx, names(gene_subset))
sachinruk
  • 9,571
  • 12
  • 55
  • 86