[R] Header auslesen und bei Regression verwenden

BiGBeN76 Johann.Magel at gmx.de
Thu Sep 22 15:13:49 CEST 2011


 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_2
                       + Covariate_n
                       , 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[3]
                       + heads[n]
                       , 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

 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.

More information about the R-help mailing list