[R] Arrays of functions or results of functions.

Gary Mallard gary.mallard at nist.gov
Mon Mar 27 19:03:56 CEST 2006


The general problem I am trying to solve is to determine if a series of 
subsets of data can be described with a single regression slope.  This 
involves fitting the data to each subset, calculating a joint slope 
followed by F tests to show that the variances are equal the final slope is 
valid.
The data for is characterized by a parameter PC (for the 4 - in this case) 
sets and a dependent variable RI and an independent variable ROH.
The data are contained in a variable "joint".
The joint has been attached and has RI, ROH and PC for each element.
The following gives the initial results:
Mline<-lm(RI[PC==1]~ROH[PC==1])
Eline<-lm(RI[PC==2]~ROH[PC==2])
Iline<-lm(RI[PC==3]~ROH[PC==3])
Pline<-lm(RI[PC==4]~ROH[PC==4])


joint_reduced <- joint;
for(i in 1:4) {
	joint_reduced$RI[joint_reduced$PC==i]<-joint$RI[joint$PC==i]-mean(joint$RI[joint$PC==1]}
AllLine<-lm(joint_reduced$RI~joint_reduced$ROH);

Now the statistics from AllLine can be compared with each of the individual 
statistics.

NOW THE QUESTION:
 From a lot of point of view it would be useful to have a parameter 
generated by
for (i in 1:4){ 	Xline[i]=lm(RI[PC==i]~ROH[PC==i])}
And now all of the work of comparison can be done with calls to Xline[i] 
rather than having to  work individually with Mline, Eline, etc.

This appears to be impossible.  The constructor for Xline[i] is not 
automatic (as it is for Mline, etc) noted above.  I cannot determine how to 
construct the Xline[i] object so that this kind of process can be 
generalized.  Is it possible?  Is there another way to set us such tests of 
multiple line linearity that is already in a package?

Comments or pointers would be appreciated.
Gary




More information about the R-help mailing list