Is there an easy way in R to create a linear regression over a model with 100 parameters in R?
Let's say we have a vector Y with 10 values and a dataframe X with 10 columns and 100 rows
In mathematical notation I would write Y = X[[1]] + X[[2]] + ... + X[[100]].
How do I write something similar in R syntax?
|
|
|||||||||||
|
|
Try this
|
|||
|
|
|
Great answers! I would add that by default, calling So in the case of the answer of @danas.zuokas you can even do
which is interpreted correctly. |
|||
|
If each row is an observation and each column is a predictor so that $Y$ is an $n$-length vector and $X$ is an $n \times p$ matrix ($p=100$ in this case), then you can do this with
If there are other columns you did not want to include as predictors, you would have to remove them from
Also, if you want to include interactions, etc.. you will need to add them manually as (for example)
or make sure they are entered as columns of |
||||
|
|
|
You can also use a combination of the Setup data: Let's imagine we have a data.frame that contains the predictor variables
Imagine also that you have a string containing the names of the predictor variables. In this case, this can easily be created using the
Apply approach: We can then construct a formula as follows:
|
|||||
|