If you explicitly convert your categorical covariates to factors before you
regress, you can use the dot notation (see help on lm) to refer to "the
rest" of the columns not otherwise specified in your formula.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
BiGBeN76 <Johann.Magel@gmx.de> wrote:
Hi.
First, a little preliminary observation: in this thread, it is indeed a
(multiple linear) regression model, the real problem is but my opinion on
general questions about R assign.
So as I said, I want to do a regression analysis, however, for several
target variables or data tables. This case, although the target variable is
always the same, but the data comes from different sectors, ie, I have
several data tables as covariates for different sectors, which can in size,
better said the number of columns or different covariates. All of these
tables but have a partially similar structure: in the first column gives the
metric target variable, (n is fixed) in the next n are the metrical
covariates and last m (m is variable) the categorical covariates can be
found. The data is read from the csv-table in a matrix "MX" as
follows:
/MX <- read.csv2("C://…/….csv", header=TRUE)/
The general R-code for stepwise linear regression is as follows:
/step(regr <- lm(Zielvariable~
Covariate_1
+ Covariate_2
+…
+ Covariate_n
+factor(Covariate_n+1)
+factor(Covariate_n+2)
+…
+factor(Covariate_n+m)
, data=MX))/
Here are the covariates, the column names and "factor" points to a
categorical covariate. I would like to make my program so that it would be
universally used for the analysis with each of these tables. To make it
work, so my idea must first be read the column headings. R may provide for a
more elegant, solution unknown to me, but I have it solved as follows:
/heads <- dimnames(MX)[[2]]/
Now, the individual "head" - values to get correct position as
follows:
/step(regr <- lm(heads[1]~
heads[2]
+ heads[3]
+…
+ heads[n]
+factor(heads[n+1])
+factor(heads[n+2])
+…
+factor(heads[n+m])
, data=Matrix))/
, where n is a fixed number, and m = length (head)-n-1.
I can well imagine how I could implement in MATLAB, but in R I'm no
professional and I hope for your help. Is there a way in the lm function a
for loop to integrate, or possibly to create an appropriate string and then
to take over the function? Or you may consider yourself, other alternative
solutions?
In any case, I am happy about every suggestion and thank you in advance.
--
View this message in context:
http://r.789695.n4.nabble.com/Header-auslesen-und-bei-Regression-verwenden-tp3833364p3833364.html
Sent from the R help mailing list archive at Nabble.com.
_____________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]