On Feb 1, 2010, at 6:29 AM, Guy Green wrote:
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:
Why not instead:
linreg=lm(Result ~ Var1^2 + Var2^2 + Var3^2,
data= Read_data)
# 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.
linreg[[1]] <- lm(Result ~ Var1^2, data= Read_data)
linreg[[2]] <- lm(Result ~ Var2^2, data= Read_data)
linreg[[3]] <- lm(Result ~ Var3^2, data= Read_data)
lapply(linreg, coef)
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.
______________________________________________
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.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
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.