Re: [R] apply regression to an array

2015-10-06 Thread David Winsemius
On Oct 6, 2015, at 10:42 AM, Adrienne Wootten wrote: > R-Helpers, > > I've seen some similar threads about this question online, but not quite > what I'm looking for. I apologize in advance if someone's already answered > this and I just can't find it online. > > Say that I have an array like

Re: [R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
Bill, Thanks a bunch that works great! A On Tue, Oct 6, 2015 at 2:56 PM, William Dunlap wrote: > Since the model matrix, cbind(1,time) is the same for all your > response variables, > you can calculate this on one call to lm, but you have to rearrange the > response > values so that each x,y s

Re: [R] apply regression to an array

2015-10-06 Thread William Dunlap
Since the model matrix, cbind(1,time) is the same for all your response variables, you can calculate this on one call to lm, but you have to rearrange the response values so that each x,y set is in one column. I think the following function does it: f <- function (time, y) { stopifnot(length(

Re: [R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
Almost forgot that function lmfunc is this: lmfunc = function(valist,input){ fitted.values(lm(valist~input)) } A On Tue, Oct 6, 2015 at 2:41 PM, Adrienne Wootten wrote: > FYI I did try something like this: > > test = apply(test3,c(1,2),lmfunc,input=t) > > but that gives me an array that is

Re: [R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
FYI I did try something like this: test = apply(test3,c(1,2),lmfunc,input=t) but that gives me an array that is 10 rows by 5 columns by 5 slices, and I need it to keep the same dimensions as test3 (5x5x10) A On Tue, Oct 6, 2015 at 1:42 PM, Adrienne Wootten wrote: > R-Helpers, > > I've seen so

[R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
R-Helpers, I've seen some similar threads about this question online, but not quite what I'm looking for. I apologize in advance if someone's already answered this and I just can't find it online. Say that I have an array like test3 in the little example code I have below: test1 = array(rep(1:1