Hello, Is there a way for R to determine the point where a confidence interval equals a specified value? For example: x = seq(1:5) y = c(5, 5, 4, 4, 3) lm = lm(y ~ x) p = predict.lm(lm, interval="confidence") matplot(p, type="b") abline(h = 3) I want to answer the question: "What is the value of x when the y-value of the lower confidence interval is equal to 3.0"? Visually, it is the place on the example where the abline intersects the lower confidence interval, or about 4.2. Can R calculate this number for me? I know that predict.lm will calculate a y-value from an x-value, but what I want is the opposite. I know the y-value, and I want to calculate the x-value. Larry Howe
Gabor Grothendieck
2006-Jun-02 15:23 UTC
[R] Intercept of confidence interval with a constant
Try this: approx(p[,"lwr"], 1:5, 3) On 6/2/06, Larry Howe <linux at comjet.com> wrote:> Hello, > > Is there a way for R to determine the point where a confidence interval equals > a specified value? For example: > > x = seq(1:5) > y = c(5, 5, 4, 4, 3) > lm = lm(y ~ x) > p = predict.lm(lm, interval="confidence") > matplot(p, type="b") > abline(h = 3) > > I want to answer the question: "What is the value of x when the y-value of the > lower confidence interval is equal to 3.0"? Visually, it is the place on the > example where the abline intersects the lower confidence interval, or about > 4.2. Can R calculate this number for me? > > I know that predict.lm will calculate a y-value from an x-value, but what I > want is the opposite. I know the y-value, and I want to calculate the > x-value. > > Larry Howe > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Larry Howe wrote:> Hello, > > Is there a way for R to determine the point where a confidence interval equals > a specified value? For example: > > x = seq(1:5) > y = c(5, 5, 4, 4, 3) > lm = lm(y ~ x) > p = predict.lm(lm, interval="confidence") > matplot(p, type="b") > abline(h = 3)You can do it this way: optimize(function(x) (predict(lm, newdata = data.frame(x=x), interval = "confidence")[,2] - 3)^2, interval=c(1, 5))$minimum but maybe you are going to solve a "calibration" problem, in fact and a completely different kind of confidence interval (namely for the x-axis)? Uwe Ligges> I want to answer the question: "What is the value of x when the y-value of the > lower confidence interval is equal to 3.0"? Visually, it is the place on the > example where the abline intersects the lower confidence interval, or about > 4.2. Can R calculate this number for me? > > I know that predict.lm will calculate a y-value from an x-value, but what I > want is the opposite. I know the y-value, and I want to calculate the > x-value. > > Larry Howe > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Ah, so I switch y with x, give it x, and ask it for y (which is actually x). Clever. I continue to be impressed with R. Thanks, Larry On Friday June 2 2006 11:23, Gabor Grothendieck wrote:> Try this: > > approx(p[,"lwr"], 1:5, 3) > > On 6/2/06, Larry Howe <linux at comjet.com> wrote: > > Hello, > > > > Is there a way for R to determine the point where a confidence interval > > equals a specified value? For example: > > > > x = seq(1:5) > > y = c(5, 5, 4, 4, 3) > > lm = lm(y ~ x) > > p = predict.lm(lm, interval="confidence") > > matplot(p, type="b") > > abline(h = 3) > > > > I want to answer the question: "What is the value of x when the y-value > > of the lower confidence interval is equal to 3.0"? Visually, it is the > > place on the example where the abline intersects the lower confidence > > interval, or about 4.2. Can R calculate this number for me? > > > > I know that predict.lm will calculate a y-value from an x-value, but what > > I want is the opposite. I know the y-value, and I want to calculate the > > x-value. > > > > Larry Howe > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html