To expand on Eik Vettorazzi's answer:

Don't use html emails. When the mailing list converts it to plain text, it 
often re-wraps lines so that your code becomes jumbled.

First, you did not define coeff. You need to add

coeff <- coef(SimpleLinearReg1)

Second, you should use the formula you used for the regression in the plot 
command or the correct order (plot uses the first variable as the x-axis and 
the second variable as the y-axis while the formula specification uses the 
variable on the left of the tilde (~) as the y-axis and the variable on the 
right of the tilde as the x-axis. Your regression predicts age (response) from 
blood pressure (explanatory) so abline() assumes age is on the y-axis and blood 
pressure is on the x-axis, but you reversed that so the line is "plotted", but 
it is outside the plot window. 

Either change the regression formula to BloodPressure~Age (which makes more 
sense than predicting age from blood pressure) or change the plot command to 
plot(BloodPressure, Age, ...) and change the xlab to ylab and ylab to xlab).

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-----Original Message-----
From: R-help <r-help-boun...@r-project.org> On Behalf Of Eik Vettorazzi
Sent: Wednesday, April 18, 2018 9:25 AM
To: CHATTON Anne <anne.chat...@hcuge.ch>; r-help@R-project.org
Subject: Re: [R] Problem with regression line

Hi Anne,
I would suggest to change the linear model to lm(BloodPressure~Age), as this 
model makes more sense in biological means (you would assume that age 
influences pressure, not vice versa) and also obeys the statistical assumption 
of weak exogeneity, that age can be measured without error, at least compared 
to error-prone bp measures.

Cheers

Am 18.04.2018 um 16:07 schrieb Gerrit Eichner:
> Hi, Anne,
> 
> assign Age and Bloodpressure in the correct order to the axes in your 
> call to plot as in:
> 
> plot(y = Age, x = BloodPressure)
> abline(SimpleLinearReg1)
> 
> 
>  Hth  --  Gerrit
> 
> ---------------------------------------------------------------------
> Dr. Gerrit Eichner                   Mathematical Institute, Room 212 
> gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
> Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany 
> http://www.uni-giessen.de/eichner
> ---------------------------------------------------------------------
> 
> 
> Am 18.04.2018 um 15:26 schrieb CHATTON Anne via R-help:
>> Hello,
>>
>> I am trying to graph a regression line using the followings:
>>
>> Age <- c(39, 47, 45, 47, 65, 46, 67, 42, 67, 56, 64, 56, 59, 34, 42, 
>> 48, 45, 17, 20, 19, 36, 50, 39, 21, 44, 53, 63, 29, 25, 69) 
>> BloodPressure <- c(144, 220, 138, 145, 162, 142, 170, 124, 158, 154, 
>> 162, 150, 140, 110, 128, 130, 135, 114, 116, 124, 136, 142, 120, 120, 
>> 160, 158, 144, 130, 125, 175) SimpleLinearReg1=lm(Age ~ 
>> BloodPressure)
>> summary(SimpleLinearReg1)
>> eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1)) 
>> plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue", main = 
>> eq, xlab = "Age (Year)", ylab = "Blood Pressure (mmHg)") 
>> abline(SimpleLinearReg1, col="red")
>> mean(Age)
>> mean(BloodPressure)
>> abline(h=142.53, col="green")
>> abline(v=45.13, col="green")
>>
>> But I cannot get the regression line. Can anybody tell me what's 
>> wrong with the codes ? I would appreciate very much. Thanks for any help.
>>
>> Anne
>>
>>     [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
>> 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.
>>
> 
> 

--
Eik Vettorazzi

Department of Medical Biometry and Epidemiology University Medical Center 
Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_____________________________________________________________________

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.) 
_____________________________________________________________________

SAVE PAPER - THINK BEFORE PRINTING
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
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.
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to