|
Hi,
I am trying to use xyplot to plot the relationship between size and day (y~x) by a food factor that has two levels, low and high. I have 3 reps per factor/day. I want the plots from each food treatment on the same axiss, so I used this code: xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1, pch=c(1,17), panel=function(x,y,groups,...){ panel.superpose(x,y,groups,...) tmp.lm<-lm(y~x) panel.abline(tmp.lm) panel.text(2, 250, label=format(tmp.lm$coefficients[2], digits=4), pos=4) } ) This produces a graph of the two treatments (open circles for the low food vs triangles for the high food) on the same plot, but only one regression line (and slope) which seems to splits the difference between the two factors (treats them as the same data set). I would like to produce a separate regression line for the data from each of the two factors (high food vs low food). Is there a way to subset the lm by the factor "food"? Louis [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
|
Please read ?panel.superpose again and pay attention to the
panel.groups argument, where this can be specified. -- Bert On Wed, Apr 18, 2012 at 12:34 PM, Louis Plough <[hidden email]> wrote: > Hi, > I am trying to use xyplot to plot the relationship between size and day > (y~x) by a food factor that has two levels, low and high. I have 3 reps per > factor/day. I want the plots from each food treatment on the same axiss, > so I used this code: > > xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1, > pch=c(1,17), > panel=function(x,y,groups,...){ > panel.superpose(x,y,groups,...) > tmp.lm<-lm(y~x) > panel.abline(tmp.lm) > panel.text(2, 250, label=format(tmp.lm$coefficients[2], digits=4), pos=4) > } > ) > This produces a graph of the two treatments (open circles for the low food > vs triangles for the high food) on the same plot, but only one regression > line (and slope) which seems to splits the difference between the two > factors (treats them as the same data set). I would like to produce a > separate regression line for the data from each of the two factors (high > food vs low food). > > Is there a way to subset the lm by the factor "food"? > > Louis > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ [hidden email] 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. |
|
If you could lead me to an example with code, that would help me figure out
how to do it for my function On Wed, Apr 18, 2012 at 3:57 PM, Louis Plough <[hidden email]> wrote: > I read it, but I guess I don't quite understand which arguments to pass > panel.groups to get different lm objects based on the two groups within > Food. > > > > On Wed, Apr 18, 2012 at 3:44 PM, Bert Gunter <[hidden email]>wrote: > >> Please read ?panel.superpose again and pay attention to the >> panel.groups argument, where this can be specified. >> >> -- Bert >> >> On Wed, Apr 18, 2012 at 12:34 PM, Louis Plough <[hidden email]> wrote: >> > Hi, >> > I am trying to use xyplot to plot the relationship between size and day >> > (y~x) by a food factor that has two levels, low and high. I have 3 reps >> per >> > factor/day. I want the plots from each food treatment on the same >> axiss, >> > so I used this code: >> > >> > xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1, >> > pch=c(1,17), >> > panel=function(x,y,groups,...){ >> > panel.superpose(x,y,groups,...) >> > tmp.lm<-lm(y~x) >> > panel.abline(tmp.lm) >> > panel.text(2, 250, label=format(tmp.lm$coefficients[2], digits=4), >> pos=4) >> > } >> > ) >> > This produces a graph of the two treatments (open circles for the low >> food >> > vs triangles for the high food) on the same plot, but only one >> regression >> > line (and slope) which seems to splits the difference between the two >> > factors (treats them as the same data set). I would like to produce a >> > separate regression line for the data from each of the two factors (high >> > food vs low food). >> > >> > Is there a way to subset the lm by the factor "food"? >> > >> > Louis >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > [hidden email] 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. >> >> >> >> -- >> >> Bert Gunter >> Genentech Nonclinical Biostatistics >> >> Internal Contact Info: >> Phone: 467-7374 >> Website: >> >> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >> > > [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
|
In reply to this post by Louis Plough
please look at the ancova function in the HH package.
On Wed, Apr 18, 2012 at 3:34 PM, Louis Plough <[hidden email]> wrote: > Hi, > I am trying to use xyplot to plot the relationship between size and day > (y~x) by a food factor that has two levels, low and high. I have 3 reps per > factor/day. I want the plots from each food treatment on the same axiss, > so I used this code: > > xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1, > pch=c(1,17), > panel=function(x,y,groups,...){ > panel.superpose(x,y,groups,...) > tmp.lm<-lm(y~x) > panel.abline(tmp.lm) > panel.text(2, 250, label=format(tmp.lm$coefficients[2], digits=4), pos=4) > } > ) > This produces a graph of the two treatments (open circles for the low food > vs triangles for the high food) on the same plot, but only one regression > line (and slope) which seems to splits the difference between the two > factors (treats them as the same data set). I would like to produce a > separate regression line for the data from each of the two factors (high > food vs low food). > > Is there a way to subset the lm by the factor "food"? > > Louis > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. > [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
|
In reply to this post by Louis Plough
On Wed, Apr 18, 2012 at 2:07 PM, Louis Plough <[hidden email]> wrote:
> If you could lead me to an example with code, that would help me figure out > how to do it for my function The states example in ?xyplot uses groups and subscripts in a panel function >> I read it, but I guess I don't quite understand which arguments to pass >> panel.groups to get different lm objects based on the two groups within >> Food. You are confused. panel.superpose != panel.groups. You probably wanted something like (and next time please provide data): x <- rep(1:10,2) y <- rnorm(20,rep(1:2,each=10)*x) g <- gl(2,10) xyplot(y~x,groups=g, panel=panel.superpose, panel.groups=function(x,y,...){ tmp.lm<-lm(y~x) panel.abline(tmp.lm) panel.text(2, coef(tmp.lm)%*%c(1,2), label=format(tmp.lm$coefficients[2], digits=4), pos=4) panel.xyplot(x,y,...) }) HTH >> >> On Wed, Apr 18, 2012 at 3:44 PM, Bert Gunter <[hidden email]>wrote: >> >>> Please read ?panel.superpose again and pay attention to the >>> panel.groups argument, where this can be specified. >>> >>> -- Bert >>> >>> On Wed, Apr 18, 2012 at 12:34 PM, Louis Plough <[hidden email]> wrote: >>> > Hi, >>> > I am trying to use xyplot to plot the relationship between size and day >>> > (y~x) by a food factor that has two levels, low and high. I have 3 reps >>> per >>> > factor/day. I want the plots from each food treatment on the same >>> axiss, >>> > so I used this code: >>> > >>> > xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1, >>> > pch=c(1,17), >>> > panel=function(x,y,groups,...){ >>> > panel.superpose(x,y,groups,...) >>> > tmp.lm<-lm(y~x) >>> > panel.abline(tmp.lm) >>> > panel.text(2, 250, label=format(tmp.lm$coefficients[2], digits=4), >>> pos=4) >>> > } >>> > ) >>> > This produces a graph of the two treatments (open circles for the low >>> food >>> > vs triangles for the high food) on the same plot, but only one >>> regression >>> > line (and slope) which seems to splits the difference between the two >>> > factors (treats them as the same data set). I would like to produce a >>> > separate regression line for the data from each of the two factors (high >>> > food vs low food). >>> > >>> > Is there a way to subset the lm by the factor "food"? >>> > >>> > Louis >>> > >>> > [[alternative HTML version deleted]] >>> > >>> > ______________________________________________ >>> > [hidden email] 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. >>> >>> >>> >>> -- >>> >>> Bert Gunter >>> Genentech Nonclinical Biostatistics >>> >>> Internal Contact Info: >>> Phone: 467-7374 >>> Website: >>> >>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >>> >> >> > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] 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. |
|
In reply to this post by Louis Plough
x <- rep(1:10,4)
y <- runif(40) z <- sample(letters[1:4],40,rep=TRUE) grp <- sample(LETTERS[1:2],40,rep=TRUE) xyplot(y~x|z, group=grp, panel = panel.superpose, panel.groups = function(...){ panel.xyplot(...) panel.lmline(...) }) Keys (legends), colors, line styles,etc, can all be customized. Read the xyplot docs (including Deepayan's book) for details. -- Bert On Wed, Apr 18, 2012 at 1:07 PM, Louis Plough <[hidden email]> wrote: > If you could lead me to an example with code, that would help me figure out > how to do it for my function > > > On Wed, Apr 18, 2012 at 3:57 PM, Louis Plough <[hidden email]> wrote: >> >> I read it, but I guess I don't quite understand which arguments to pass >> panel.groups to get different lm objects based on the two groups within >> Food. >> >> >> >> On Wed, Apr 18, 2012 at 3:44 PM, Bert Gunter <[hidden email]> >> wrote: >>> >>> Please read ?panel.superpose again and pay attention to the >>> panel.groups argument, where this can be specified. >>> >>> -- Bert >>> >>> On Wed, Apr 18, 2012 at 12:34 PM, Louis Plough <[hidden email]> wrote: >>> > Hi, >>> > I am trying to use xyplot to plot the relationship between size and day >>> > (y~x) by a food factor that has two levels, low and high. I have 3 reps >>> > per >>> > factor/day. I want the plots from each food treatment on the same >>> > axiss, >>> > so I used this code: >>> > >>> > xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1, >>> > pch=c(1,17), >>> > panel=function(x,y,groups,...){ >>> > panel.superpose(x,y,groups,...) >>> > tmp.lm<-lm(y~x) >>> > panel.abline(tmp.lm) >>> > panel.text(2, 250, label=format(tmp.lm$coefficients[2], digits=4), >>> > pos=4) >>> > } >>> > ) >>> > This produces a graph of the two treatments (open circles for the low >>> > food >>> > vs triangles for the high food) on the same plot, but only one >>> > regression >>> > line (and slope) which seems to splits the difference between the two >>> > factors (treats them as the same data set). I would like to produce a >>> > separate regression line for the data from each of the two factors >>> > (high >>> > food vs low food). >>> > >>> > Is there a way to subset the lm by the factor "food"? >>> > >>> > Louis >>> > >>> > [[alternative HTML version deleted]] >>> > >>> > ______________________________________________ >>> > [hidden email] 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. >>> >>> >>> >>> -- >>> >>> Bert Gunter >>> Genentech Nonclinical Biostatistics >>> >>> Internal Contact Info: >>> Phone: 467-7374 >>> Website: >>> >>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >> >> > -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ [hidden email] 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. |
| Powered by Nabble | Edit this page |
