Reputation: 347
I wanted to use polynomial regression on my data, but I have more than 10 predictors and my predictors' name change on my samples. I also used linear regression on my data in the below code:
model_lm = lm(gene_expression ~ ., data = donor_snp_sample)
summary_lm <- summary(model_lm)
I used "gene_expression ~ ."
in my code, but I don't know how to use the same format in polynomial regression. Can you help me?
thanks a lot
Upvotes: 0
Views: 940
Reputation: 269624
The question is ambiguous as to the specific model desired but here is one possible model where we independently take a quadratic in each independent variable.
fo <- reformulate(sprintf("poly(%s, 2)", names(airquality)[-1]), "Ozone")
fo
## Ozone ~ poly(Solar.R, 2) + poly(Wind, 2) + poly(Temp, 2) + poly(Month,
## 2) + poly(Day, 2)
lm(fo, na.omit(airquality))
giving:
Call:
lm(formula = fo, data = na.omit(airquality))
Coefficients:
(Intercept) poly(Solar.R, 2)1 poly(Solar.R, 2)2 poly(Wind, 2)1
42.10 64.80 -24.13 -124.10
poly(Wind, 2)2 poly(Temp, 2)1 poly(Temp, 2)2 poly(Month, 2)1
89.41 128.16 55.40 -18.45
poly(Month, 2)2 poly(Day, 2)1 poly(Day, 2)2
-32.10 27.20 11.87
or write it like this if it is desired to see the formula written out on the Call: line of the output.
do.call("lm", list(fo, quote(na.omit(airquality))))
giving:
Call:
lm(formula = Ozone ~ poly(Solar.R, 2) + poly(Wind, 2) + poly(Temp,
2) + poly(Month, 2) + poly(Day, 2), data = na.omit(airquality))
Coefficients:
(Intercept) poly(Solar.R, 2)1 poly(Solar.R, 2)2 poly(Wind, 2)1
42.10 64.80 -24.13 -124.10
poly(Wind, 2)2 poly(Temp, 2)1 poly(Temp, 2)2 poly(Month, 2)1
89.41 128.16 55.40 -18.45
poly(Month, 2)2 poly(Day, 2)1 poly(Day, 2)2
-32.10 27.20 11.87
Upvotes: 1