Martin Batholdy
2009-Mar-08 01:18 UTC
[R] plot confidence limits of a regression line - problem
hi, I don't know what I am doing wrong, but with that code; x1 <- c(1.60, 0.27, 0.17, 1.63, 1.37, 2.00, 0.90, 1.07, 0.89, 0.43, 0.37, 0.59, 0.47, 1.83, 1.79, 0.90, 0.72, 1.83, 0.23, 1.97, 2.03, 2.19, 2.03, 0.86) x2 <- c(1.30, 0.24, 0.20, 0.50, 1.33, 1.87, 1.30, 0.75, 1.07, 0.43, 0.37, 0.87, 1.40, 1.37, 1.63, 0.80, 0.57, 1.60, 0.39, 2.03, 1.90, 2.07, 1.93, 0.93) model <- lm(x1 ~ x2) predict(model, newdata=data.frame(x=seq(0,4)), ,interval = c("confidence"), level = 0.90,type="response") I get an error message saying "newdate has four lines, but the variable found has 24" what is wrong in the code? thanks! [[alternative HTML version deleted]]
David Winsemius
2009-Mar-08 01:42 UTC
[R] plot confidence limits of a regression line - problem
It is not an error but rather a warning. As you should have seen, R went ahead and returned estimates for 24 predicted values for x1 for arguments to the formula of x2. In R errors and warnings are very different. You are expected to post full console messages to prevent this sort of confusion. In this case the warning puts you on notice that your offer to newdata= was not acceptable. You did not construct it with names that match those in the formula which was used to create model. Please follow the links offered and read the Posting Guide: -- David Winsemius On Mar 7, 2009, at 8:18 PM, Martin Batholdy wrote:> hi, > > > I don't know what I am doing wrong, > > but with that code; > > > x1 <- c(1.60, 0.27, 0.17, 1.63, 1.37, 2.00, 0.90, 1.07, 0.89, 0.43, > 0.37, 0.59, > 0.47, 1.83, 1.79, 0.90, 0.72, 1.83, 0.23, 1.97, 2.03, 2.19, 2.03, > 0.86) > > x2 <- c(1.30, 0.24, 0.20, 0.50, 1.33, 1.87, 1.30, 0.75, 1.07, 0.43, > 0.37, 0.87, > 1.40, 1.37, 1.63, 0.80, 0.57, 1.60, 0.39, 2.03, 1.90, 2.07, 1.93, > 0.93) > > model <- lm(x1 ~ x2) > > predict(model, newdata=data.frame(x=seq(0,4)), ,interval > c("confidence"), level = 0.90,type="response") > > > > > I get an error message saying "newdate has four lines, but the > variable found has 24" > > > what is wrong in the code? > > > thanks! > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
Eik Vettorazzi
2009-Mar-09 10:30 UTC
[R] plot confidence limits of a regression line - problem
Hi, the predict-function is not very good in guessing names from a given new dataset. So if you want to predict x1 from some new x2 values, your newdata argument should contain some x2 - values. predict(model, newdata=data.frame(x2=seq(0,4)), interval = c("confidence"), level = 0.90,type="response") without that, predict uses your old x2 values and issues a warning message. Martin Batholdy schrieb:> hi, > > > I don't know what I am doing wrong, > > but with that code; > > > x1 <- c(1.60, 0.27, 0.17, 1.63, 1.37, 2.00, 0.90, 1.07, 0.89, 0.43, > 0.37, 0.59, > 0.47, 1.83, 1.79, 0.90, 0.72, 1.83, 0.23, 1.97, 2.03, 2.19, 2.03, 0.86) > > x2 <- c(1.30, 0.24, 0.20, 0.50, 1.33, 1.87, 1.30, 0.75, 1.07, 0.43, > 0.37, 0.87, > 1.40, 1.37, 1.63, 0.80, 0.57, 1.60, 0.39, 2.03, 1.90, 2.07, 1.93, 0.93) > > model <- lm(x1 ~ x2) > > predict(model, newdata=data.frame(x=seq(0,4)), ,interval = > c("confidence"), level = 0.90,type="response") > > > > > I get an error message saying "newdate has four lines, but the > variable found has 24" > > > what is wrong in the code? > > > thanks! > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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 Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790