Hello, I appreciate this is likely to be an easy question. I am trying to obtain the residuals from a linear regression where the line is forced to have a 1:1 relationship. An example of the data: A<-c(0.9803922, 1.3850416, 0.8241758, 0.0000000, 0.4672897, 1.1904762, 0.0000000, 0.9456265, 1.5151515) B<-c(1.3229572, 1.9471488, 1.3182674, 0.7007708, 1.0185740, 1.0268562, 0.8695652, 0.3016591, 1.9667171) plot(A, B, ylim=c(0,2), xlim=c(0,2)) abline(0,1, col="lightgrey", lty="dashed",lwd=2)#1:1 relationship = what I want to use in the lm() #Normal regression AB<-lm(A~B) #plot regression line abline(lm(AB)) How can I force the regression to have a 1:1 relationship, I assume it is to do with offset() but I have somewhat fried my brain trying numerous variations and I am not convinced any are correct. I was also hoping the plot function would show me that the calculation is correct, but any time I use the offset() command there is no line plotted? Any hints or tips would be much appreciated! Ross -- View this message in context: http://r.789695.n4.nabble.com/Force-regression-line-to-a-1-1-relationship-tp3809733p3809733.html Sent from the R help mailing list archive at Nabble.com.
Just to clarify things before trying to answer: by a "1:1 relationship" do you mean you want the regression slope to be equal to 1 "no matter what"? Michael On Tue, Sep 13, 2011 at 7:03 AM, RCulloch <ross.culloch@dur.ac.uk> wrote:> Hello, > > I appreciate this is likely to be an easy question. I am trying to obtain > the residuals from a linear regression where the line is forced to have a > 1:1 relationship. > > An example of the data: > > A<-c(0.9803922, 1.3850416, 0.8241758, 0.0000000, 0.4672897, 1.1904762, > 0.0000000, 0.9456265, > 1.5151515) > B<-c(1.3229572, 1.9471488, 1.3182674, 0.7007708, 1.0185740, 1.0268562, > 0.8695652, 0.3016591, 1.9667171) > > plot(A, B, ylim=c(0,2), xlim=c(0,2)) > abline(0,1, col="lightgrey", lty="dashed",lwd=2)#1:1 relationship = what I > want to use in the lm() > > #Normal regression > AB<-lm(A~B) > > #plot regression line > abline(lm(AB)) > > > How can I force the regression to have a 1:1 relationship, I assume it is > to > do with offset() but I have somewhat fried my brain trying numerous > variations and I am not convinced any are correct. I was also hoping the > plot function would show me that the calculation is correct, but any time I > use the offset() command there is no line plotted? > > Any hints or tips would be much appreciated! > > Ross > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Force-regression-line-to-a-1-1-relationship-tp3809733p3809733.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org 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]]
yes, that is correct. The idea being that I want to know the residuals of the data points compared to a 1:1 line (as shown in the plot), if that makes sense? I appreciate that this might not be considered a typical approach, and it would probably take a while to explain (defend) why I am doing it! -- View this message in context: http://r.789695.n4.nabble.com/Force-regression-line-to-a-1-1-relationship-tp3809733p3810045.html Sent from the R help mailing list archive at Nabble.com.
Dear Ross, lm(y ~ 0 + offset(x)) will do the trick, but the resulting model has no coefficient estimates and thus can't be used with abline(). You can, e.g., get predictions from the model, but I'm not sure what real use it will be to you. I hope this helps, John -------------------------------- John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of RCulloch > Sent: September-13-11 7:03 AM > To: r-help at r-project.org > Subject: [R] Force regression line to a 1:1 relationship > > Hello, > > I appreciate this is likely to be an easy question. I am trying to > obtain the residuals from a linear regression where the line is forced > to have a > 1:1 relationship. > > An example of the data: > > A<-c(0.9803922, 1.3850416, 0.8241758, 0.0000000, 0.4672897, 1.1904762, > 0.0000000, 0.9456265, > 1.5151515) > B<-c(1.3229572, 1.9471488, 1.3182674, 0.7007708, 1.0185740, 1.0268562, > 0.8695652, 0.3016591, 1.9667171) > > plot(A, B, ylim=c(0,2), xlim=c(0,2)) > abline(0,1, col="lightgrey", lty="dashed",lwd=2)#1:1 relationship > what I want to use in the lm() > > #Normal regression > AB<-lm(A~B) > > #plot regression line > abline(lm(AB)) > > > How can I force the regression to have a 1:1 relationship, I assume it > is to do with offset() but I have somewhat fried my brain trying > numerous variations and I am not convinced any are correct. I was also > hoping the plot function would show me that the calculation is correct, > but any time I use the offset() command there is no line plotted? > > Any hints or tips would be much appreciated! > > Ross > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Force- > regression-line-to-a-1-1-relationship-tp3809733p3809733.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.
Dear Ross, But the residuals are just y - x. Best, John> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of RCulloch > Sent: September-13-11 9:19 AM > To: r-help at r-project.org > Subject: Re: [R] Force regression line to a 1:1 relationship > > yes, that is correct. The idea being that I want to know the residuals > of the data points compared to a 1:1 line (as shown in the plot), if > that makes sense? I appreciate that this might not be considered a > typical approach, and it would probably take a while to explain > (defend) why I am doing it! > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Force- > regression-line-to-a-1-1-relationship-tp3809733p3810045.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Patrick Breheny > > The latter type of plot is called a "partial regression plot" > or "added variable plot". They are discussed in any > regression textbook, as well as wikipedia and probably dozens > of other web sites.They are also available in the car package. S Ellison******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
Dear S Ellison, If I understand correctly what you said, a plot of residuals against an X is not an added-variable plot. An added variable plot is constructed by regressing Y on all the Xs but the focal X, and regressing the focal X on all the other Xs; then the residuals from the first regression are plotted against the residuals from the second. As Denis Cook has shown, AV plots, while very useful for visualizing influence and leverage on the coefficients (and for other purposes) are not good nonlinearity diagnostics; for that purpose component+residual (partial residual) plots and their variations are better. Both added-variable and component+residual plots are available in the car package; see ?avPlots, ?crPlots. Best, John ------------------------------------------------ John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Wed, 14 Sep 2011 16:07:24 +0100 S Ellison <S.Ellison at LGCGroup.com> wrote:> > > > -----Original Message----- > > From: r-help-bounces at r-project.org > > [mailto:r-help-bounces at r-project.org] On Behalf Of Patrick Breheny > > > > The latter type of plot is called a "partial regression plot" > > or "added variable plot". They are discussed in any > > regression textbook, as well as wikipedia and probably dozens > > of other web sites. > > They are also available in the car package. > > S Ellison******************************************************************* > This email and any attachments are confidential. Any use...{{dropped:8}} > > ______________________________________________ > R-help at r-project.org 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.