The newdata argument to predict should be a data.frame (or environment or list) containing the variables that are on the right side of the formula (the predictors). In your case that means it should have a variable called 'Concentration'. Since it didn't have such a variable (it contained only 'Replica.1'), predict found a variable called 'Concentration' in the global environment and used it for the prediction.
To help avoid this problem, do not use the idiom Conc <- c(.1, .4, .9) Std <- c(2, 5, 7) myData <- data.frame(Conc, Std) to make your data.frame: it leaves unwanted global variables around. Instead use myData <- data.frame( Conc = c(.1, .4, .9), Std = c(2, 5, 7)) Then, if your newdata argument to predict is inappropriate you will get a complaint that predict cannot find 'Conc'. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Julen Tomás Cortazar > Sent: Friday, September 13, 2013 6:16 AM > To: r-help@r-project.org > Subject: [R] regression > > I am sorry, > > > > I have a problem. When I use the "predict" function I am always obtaining the > same > result and I don't know why. In adittion, the intercept and the residual > values I get are > wrong too. > > > > std: > > > > [1] 0.068 0.117 0.167 0.269 0.470 0.722 > > > > > > Concentration: > > > > [1] 3.90625 7.81250 15.62500 31.25000 62.50000 125.00000 > > > > replica1: > > > > Replica.1 > 1 0.080 > 2 1.325 > 3 1.309 > 4 1.072 > 5 1.595 > 6 1.384 > > replica2: > > Replica.2 > 1 0.098 > 2 1.335 > 3 1.271 > 4 1.187 > 5 1.569 > 6 1.268 > > > > > regresion <- lm(std ~ Concentration, mydata): > > > > Call: > lm(formula = std ~ Concentration, data = mydata) > > Residuals: > 1 2 3 4 5 6 > -0.035531 -0.007440 0.000742 0.019106 0.052834 -0.029711 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) 0.0826219 0.0208118 3.97 0.016539 * > Concentration 0.0053527 0.0003532 15.15 0.000111 *** > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 0.0366 on 4 degrees of freedom > Multiple R-squared: 0.9829, Adjusted R-squared: 0.9786 > F-statistic: 229.6 on 1 and 4 DF, p-value: 0.0001106 > > > > > > > predict(regresion, replica1, int = "p") > fit lwr upr > 1 0.1035309 -0.012098349 0.2191602 > 2 0.1244399 0.009958707 0.2389212 > 3 0.1662580 0.053716164 0.2787998 > 4 0.2498941 0.139724612 0.3600636 > 5 0.4171663 0.305409665 0.5289230 > 6 0.7517107 0.614489312 0.8889322 > > > predict(regresion, replica2, int = "p") > fit lwr upr > 1 0.1035309 -0.012098349 0.2191602 > 2 0.1244399 0.009958707 0.2389212 > 3 0.1662580 0.053716164 0.2787998 > 4 0.2498941 0.139724612 0.3600636 > 5 0.4171663 0.305409665 0.5289230 > 6 0.7517107 0.614489312 0.8889322 > > > So, anyone knows what is happening to me? > > Thank you very much! > > > > > > > > > > > This e-mail comes from CIC bioGUNE. The e-mail and any files transmitted with > it are > confidential and intended solely for the use of the individual or entity to > whom they are > addressed. Any unauthorised dissemination or copying of this e-mail or its > attachments, > and any use or disclosure of any information contained in them, is strictly > prohibited and > may be illegal. If you have received this e-mail in error, please notify or > telephone + 34 > 944 06 13 00 and delete it from your system. > > Please consider the environment before printing this email > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.