Hello, Anne,
just a few quick hints because I need to run.
First, try to format you R-code in emails like this
with adequate line breaks.
Second, if you boil down your problem to the crucial point
(and not just pack an email with very specific code) more
people may be more willing to respond.
Third, just to be sure: This list is not for home work.
Two more remarks see inline below.
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 20.04.2018 um 10:32 schrieb CHATTON Anne via R-help:> Hi R folks,
> In my previous post I forgot to mention that I was new to R. I was
> really grateful for your quick help. I have two further questions:
> 1) In the graph of a regression line I would like to show one specific
residual yi obs - yi pred (let's take the person whose residual is 76). How
do I add a bracket to this vertical distance and name it? I'am getting stuck
after the "textxy" function.
> 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)
> mean(Age)
> mean(BloodPressure)
> SimpleLinearReg1 <- lm(BloodPressure ~ Age)
> summary(SimpleLinearReg1)
> coeff <-coefficients(SimpleLinearReg1)
> coeff
> eq <- as.formula(
> paste0("y ~ ", round(coefficients(SimpleLinearReg1)[1],2),
"",
> paste(sprintf(" %+.2f*%s ",
> coefficients(SimpleLinearReg1)[-1],
> names(coefficients(SimpleLinearReg1)[-1])),
> collapse="")))
> eq <- paste0("y = ", round(coeff[2],1), "x + ",
round(coeff[1],1))
> plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue",
> main = "Graphe de la relation entre l'?ge et la pression
art?rielle",
> xlab = "Age (ann?e)", ylab = "Pression art?rielle
(mmHg)")
> abline(SimpleLinearReg1, col="red")
> res <- signif(residuals(SimpleLinearReg1), 2)
> pre <- predict(SimpleLinearReg1)
> segments(Age, BloodPressure, Age, pre, col="red")
> library(calibrate)
> textxy(Age, BloodPressure, res, cex=0.7)
I don't understand what mean by "to add a bracket", but why
don't you just place a "name" next to the vertical line at
residual # 76 using the function text?
2)>
> 2) I also need your help plotting a hyperplan for a multiple
> regression and here I am really stuck...
This is a bit more complicated. Learn, e.g., about function persp
or search for "plot regression surface with r" and find, e.g.,
https://stackoverflow.com/questions/7863906/plot-regression-surface#7864088
as the first hit.
> inc <- c(25000, 28000, 17500, 30000, 25000, 32000, 30000, 29000, 26000,
40000)
> age <- c(60, 36, 21, 35, 33, 43, 29, 45, 41, 48)
> educ <- c(12, 12, 13, 16, 16, 12, 13, 15, 15, 20)
> MultLinearReg1 <- lm(inc ~ age + educ)
> summary(MultLinearReg1)
>
> Thank you so much!
>
> ______________________________________________
> 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.
>