Regression in R, creating new dataframe from excel file.

Hello, I have an excel table consisting of 6 independent variables (x) and 12 dependent variables (y) and I have to do linear regression.
I have written the code in details for the twelve dependent variables against one of the independent ones, i.e., y1 vs x1, y2 vs x1, ..., y12 vs x1, obtained their plots, coloured then individually and producing the summary statistics.

x1 <-read_excel("filename")
plot(x1, y1, type="n", main="y1 vs x1", xlab="x1", ylab="y1", xlim=c(54,59), ylim=c(0,10))


But it is really time consuming so I am working on a loop to do the followings:

  1. To carry out all the regression and plot the regression line for each one of the 12 dependent variables against the independent ones, i.e., I have to obtain 6 different graphs each with 12 plots.

I am trying to use the function data.frame to select the columns from my excel file to plots against each other using:


Regression <- read_excel("filename")

y1 <- data_frame(x1, x2, x3, x4, x5, x6)

data %>% 
  group_by(x1) %>% 
  do(tidy(lm(x2 ~ x3, data = .))) %>% 
  select(variable = x1, term, t_stat = statistic)
  1. Since I have 12 plots on a single graph, col=1,...12, is giving twice many of the colors, I have tried using rainbow but getting lots of errors.

  2. I want to store all the summary, R-squared, Adj R-Squared, ... in a new excel table along with the regression equations.

A post was merged into an existing topic: loop Regression in R, creating new dataframe from excel file.