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]]
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.eichner at 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 at 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. >-- Best regards -- Gerrit Best regards -- Gerrit Eichner Hth -- Gerrit Viele Gr??e -- Gerrit Viele Gr??e -- Gerrit Eichner Viele Gr??e -- GE Freundliche Gr??e -- Gerrit Eichner Freundliche Gr??e -- GE Gr??e -- Gerrit Gr??e -- Gerrit Eichner Gr??e -- GE Gru? -- G --------------------------------------------------------------------- Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eichner at 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
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.eichner at 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 at 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
Hi Gerrit! Thank you so much! I mistakenly reversed the order of the variables of the regression. Actually what I meant to write was: lm(BloodPressure ~ Age). Best, Anne -----Message d'origine----- De?: Gerrit Eichner [mailto:Gerrit.Eichner at math.uni-giessen.de] Envoy??: mercredi 18 avril 2018 16:08 ??: CHATTON Anne; r-help at R-project.org Objet?: Re: [R] Problem with regression line 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.eichner at 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 at 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. >-- Best regards -- Gerrit Best regards -- Gerrit Eichner Hth -- Gerrit Viele Gr??e -- Gerrit Viele Gr??e -- Gerrit Eichner Viele Gr??e -- GE Freundliche Gr??e -- Gerrit Eichner Freundliche Gr??e -- GE Gr??e -- Gerrit Gr??e -- Gerrit Eichner Gr??e -- GE Gru? -- G --------------------------------------------------------------------- Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eichner at 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 ---------------------------------------------------------------------