[R] within-subject stdized regression w missing data
Jonathan Baron
baron at cattell.psych.upenn.edu
Sat Apr 21 12:33:37 CEST 2001
I am looking for an elegant solution to the following problem. I
have one that works, but it is ugly.
In a questionnaire, each of 80 subjects answered 8 questions
about each of 30 different behaviors. My main method of analysis
is within-subject regression, in which I predict the answer to
one of the 8 questions from answers to some of the other
questions - different subsets for different analyses. The 30
behaviors are the units of analysis. (That is, there is an 8x30
matrix for each subject. One of the 8 variables is the dependent
variable, and some of the others are predictors.)
There are lots of missing data, sometimes so much as to make a
given subject's regression impossible for one analysis.
I also want standardized regression weights. The standardization
should include just the items used in each regression. I've been
using scale() on all the variables in order to get standardized
weights, but it is not a simple matter to arrange this so as to
get just the right subset of the 30 behaviors for each
regression, because the behaviors that are missing for one
analysis are not necessarily missing for another (even for the
same subject).
I have been using a loop to do the regressions, e.g.,
for (i in 1:numberofsubjects)
r.v1[i,] <- lm(v1[i,] ~ v2[i,] + v3[i,] + v4[i,])$coef[2:4]
where v1 etc. are already selected and rescaled appropriately for
the variables included. This gives me a matrix of the regression
coefficients, which I can then test across subjects.
One thing I've got to do is make sure that each subject's
regression will actually run, or omit the ones that won't, or
else the whole thing bombs. I have been unable to get lm() to
proceed without doing this with several extra steps. (I did read
the help page.)
I've thought about modifing the lm() function - this would be my
first attempt at such a thing - or else putting the whole thing
in some kind of wrapper that uses scale() on a matrix. (I've
been using it on vectors.) But the matrix would have to have
just the right entries in the end.
I'm writing just in case there is some really obvious solution to
this that I'm missing.
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~jbaron
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list