[R] Manipulating data, and performing repeated simple regressions, not multiple regression

Guy Green guygreen at netvigator.com
Mon Feb 1 12:29:26 CET 2010


I have a simple table of data:

  Result    Var1    Var2    Var3
1   0.10    0.78    0.12    0.38
2   0.20    0.66    0.39    0.12
3   0.10    0.83    0.09    0.52
4   0.15    0.41    0.63    0.95
5   0.60    0.88    0.91    0.86
6  -0.02    0.14    0.69    0.94

I am trying to achieve two things:

1) Manipulate this data so that I have the "Result" data unchanged, and all
the other data (the Var1, Var2 & Var3 columns) squared.  I can achieve this
(see code below), but I then can't use the output in the way I expect.

2) I want to get as outputs the separate regressions of Var1 to Result, Var2
to Result, etc.  I.e. separate single-variable regressions, NOT a multiple
regression.

The code I have so far (with the simple data above in this attached file
"sample-regression.txt") 
http://n4.nabble.com/file/n1458694/sample-regression.txt
sample-regression.txt  is:


Read_data=read.table("C:/sample-regression.txt", head = T)
Resultnew=Read_data[,1]
Varsquared = Read_data[,-1]^2
reg_data=cbind(Resultnew,Varsquared)
#If I look at the output of this (reg_data), it looks how I want it to look.
#However, I can't use it: when I perform even a regular multiple regression
on it, I get the error message:
#   Error in model.frame.default(formula = Resultnew ~ Var1 + Var2 + Var3, 
: 
#     'data' must be a data.frame, not a matrix or an array
#e.g.:
linreg=lm(Resultnew~Var1+Var2+Var3, data=reg_data)

So: 1) is there a better way to calculate the squared data, so that I can
use the output more flexibly, and 2) can I perform the calculation not as a
multiple regression, but to get separate regressions.  

Ideally the output should be something like:

Var1	0.4394
Var2	0.4463
var3	0.0631

(These are the actual regression coefficients, if done separately, on the
data after the Var columns have been squared.)

Thanks,

Guy
-- 
View this message in context: http://n4.nabble.com/Manipulating-data-and-performing-repeated-simple-regressions-not-multiple-regression-tp1458694p1458694.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list