# [R] Arrays of functions or results of functions.

Gabor Grothendieck ggrothendieck at gmail.com
Mon Mar 27 19:47:41 CEST 2006

```Is your question how to run a regression with separate slopes
and then with one slope and then to complare them?  If that
is it here is an example:

# test data - ind is factor which defines the groups
set.seed(1)
y1 <- 10 + 20 * seq(100) + rnorm(100)
y2 <- -200 + 35 * seq(100) + rnorm(100)
yy <- pmax(y1, y2)
ind <- factor(y1 > y2)

# lm.N has N slopes
lm.1 <- lm(yy ~ ind + seq(100) - 1)
lm.2 <- lm(yy ~ ind/seq(100)-1)
lm.1
lm.2
anova(lm.1, lm.2)

On 3/27/06, Gary Mallard <gary.mallard at nist.gov> wrote:
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

```

More information about the R-help mailing list