How to work with linear regression and confidence intervals in R?

I would like to know that the commands used in R work with linear regression tasks and confidence intervals, and why they are incorrect.

For example, let's say we have the following data:

A <- c(12,11,12,15,13,16,13,18,11,14) # this is the width
B <- c(50,51,62,45,63,76,53,68,51,74) # this is the height

We performed a linear regression describing variable B (height) of variable A (width). The question is to find a 90% confidence interval with an average height (B) that has 14 widths (A).

I know how to do linear regression in R, lm(B~A)and I get an equation like this B = a + A * c , where B and A are my variables a is the interception ..

What I tried was:

  • Find the height using the width they give me: B= a + (14)*c= MU (for example)
  • Finally, to get the interval: t.test(B, mu = MU, conf.level=0.9)but, unfortunately, this is not true ..
+4
source share
1 answer

Try the following:

> m <- lm(B~A)
> predict(m, newdata=data.frame(A=14), interval='confidence', level=0.9)
       fit      lwr      upr
1 60.58495 54.72854 66.44135
+4
source

All Articles