-1

If I have a dataset wherein one column is a list, how can I run linear regression including only specific variables in that column?

Example.Column <- (DrugA1, Drug A2, DrugA2, DrugA3, DrugB1, DrugB2,
                 DrugB3, No.Drug, Drug A2, No.Drug, DrugB3)
VolMeasure <- c("VL.of.region1", "VL.of.region2", "VL.of.region3")

Sorry for the confusion here - there would be a for-loop to have the lm go through each VolMeasure for the response variable - so there would be 3 regressions in the example.

Example.lm <- lm(VolMeasure ~ DrugA1|DrugA2|DrugA3, data=dataset)

From this, I need to also figure out how I can do such a thing for multiple variables in one linear regression, so for example if I add a dieting variable

Diet.variable<-("Atkins", "Mediterranean", "Caloric Restriction", "None")
Example2.lm<-lm(VolMeasure ~ DrugA1|DrugA2|DrugA3 & Diet.variable=c("Atkins"), data=dataset)
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
  • Perhaps you should ?ls and look at the example. It is simple "+" notation. – won782 Aug 13 '14 at 16:18
  • What is your actual response here. You can't have multiple responses for a simple linear regression. Your example is very much incomplete and confusing. Please try to make a proper [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – MrFlick Aug 13 '14 at 17:57
  • I'm trying to run linear regression on a portion of a dataset - so only looking at the participants that are on one of the A drugs (drug A is a class, and A1/2/3 are subclasses), and how that effects volume measurements. Because of the nature of what I want to do after this, sub-setting is potentially problematic as it separates the data. – Brandy Riedel Aug 13 '14 at 23:58
  • If by chance someone comes across this same sort of problem, here is my solution: Example.lm <- lm(VL.of.region1 ~ Example.Column, data = MyData[MyData$Example.Column %in% c("DrugA1", "DrugA2", "DrugA3"), ]) – Brandy Riedel Aug 14 '14 at 04:26
  • The question does not refer to Linear Programming. – Christian Aug 14 '14 at 14:17

1 Answers1

0

You should try to make a subset dataset:

    subData <- subset(yourData, 
Example.Column %in% c("DrugA1", "DrugA2", "DrugA3") & Diet.Variable == "Atkins")

    lm( VolMeasure ~ Example.Column + Diet.Variable, data = subData)
Marcin
  • 7,834
  • 8
  • 52
  • 99