[R] predicting values from multiple regression
Hey List, I did a multiple regression and my final model looks as follows: model9<-lm(calP ~ nsP + I(st^2) + distPr + I(distPr^2)) Now I tried to predict the values for calP from this model using the following function: xv<-seq(0,89,by=1) yv<-predict(model9,list(distPr=xv,st=xv,nsP=xv)) The predicted values are however strange. Now I do not know weather just the model does not fit the data (actually all coefficiets are significant and the plot(model) shows a good shape) or wether I did something wrong with my prediction command. Does anyone have an idea??? -- Thanks a lot, Anna __ 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.
Re: [R] predicting values from multiple regression
Dear Ista! Thank you for replying. The point you made is exactly what's the problem: I want to predict the values at different points in space. calP stands for the water content at each sampling point (n=90) but I don't quite understand what R does. calP is my vector of measured data and I thought with the predict function the programm would calculate a value from the model function for every value of calP... ? 2011/3/20 Ista Zahn : > Hi Anna, > > On Sun, Mar 20, 2011 at 2:54 PM, Anna Lee wrote: >> Hey List, >> >> I did a multiple regression and my final model looks as follows: >> >> model9<-lm(calP ~ nsP + I(st^2) + distPr + I(distPr^2)) >> >> Now I tried to predict the values for calP from this model using the >> following function: >> >> xv<-seq(0,89,by=1) >> yv<-predict(model9,list(distPr=xv,st=xv,nsP=xv)) > > The second argument to predict.lm is newdata, which should be a > data.frame. see ?predict.lm. > > Beyond that though, I'm not sure what you are trying to accomplish. > The way you've set this up you would get predicted values for cases > like > > distPr st nsp > 0 0 0 > 1 1 1 > 2 2 2 > . . . > 89 89 89 > > > Is that really what you want? > > Best, > Ista >> >> The predicted values are however strange. Now I do not know weather >> just the model does not fit the data (actually all coefficiets are >> significant and the plot(model) shows a good shape) or wether I did >> something wrong with my prediction command. Does anyone have an >> idea??? >> >> -- >> >> >> Thanks a lot, Anna >> >> __ >> 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. >> > > > > -- > Ista Zahn > Graduate student > University of Rochester > Department of Clinical and Social Psychology > http://yourpsyche.org > -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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.
Re: [R] predicting values from multiple regression
Dennis: Thank you so much! I got it now - it just works perfectly. Thanks a lot! Anna 2011/3/21 Dennis Murphy : > Hi: > > To amplify Ista's and David's comments: > > (1) You should not be inputting separate vectors into lm(), especially if > you intend to do prediction. They should be combined into a data frame > instead. This is not a requirement, but it's a much safer strategy for > modeling in R. > (2) Your covariate st does not have a linear component. It should, > particularly if this is an empirical model rather than a theoretical one. > (3) You should be using poly(var, 2) to create orthogonal columns in the > model matrix for the variables that are to contain quadratic terms. > (4) The newdata = argument of predict.lm() [whose help page you should read > carefully] requires a data frame with columns having precisely the same > variable names as exist in the RHS of the model formula in lm(). > > Example: > dd <- data.frame(y = rnorm(50), x1 = rnorm(50), x2 = runif(50, -2, 2), x3 = > rpois(50, 10)) > > # fit yhat = b0 + b1 * x1 + b2 * x1^2 + b3 * x2 + b4 * x3 + b5 * x3^2 > mod <- lm(y ~ poly(x1, 2) + x2 + poly(x3, 2), data = dd) > > # Note that the names of the variables in newd are the same as those on the > RHS of the formula in mod > newd <- data.frame(x1 = rnorm(5), x2 = runif(5, -2, 2), x3 = rpois(5, > 10)) # new data points > # Append predictions to newd > cbind(newd, predict(mod, newdata = newd)) # predictions at new > data points > > # To just get predictions at the observed points, all you need is > predict(mod) > > HTH, > Dennis > > On Sun, Mar 20, 2011 at 11:54 AM, Anna Lee wrote: >> >> Hey List, >> >> I did a multiple regression and my final model looks as follows: >> >> model9<-lm(calP ~ nsP + I(st^2) + distPr + I(distPr^2)) >> >> Now I tried to predict the values for calP from this model using the >> following function: >> >> xv<-seq(0,89,by=1) >> yv<-predict(model9,list(distPr=xv,st=xv,nsP=xv)) >> >> The predicted values are however strange. Now I do not know weather >> just the model does not fit the data (actually all coefficiets are >> significant and the plot(model) shows a good shape) or wether I did >> something wrong with my prediction command. Does anyone have an >> idea??? >> >> -- >> >> >> Thanks a lot, Anna >> >> __ >> 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. > > -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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.
Re: [R] predicting values from multiple regression
Dennis: thank you so much! I got it now and it works just perfectly. Thanks a lot to the others too! Anna 2011/3/21 Dennis Murphy : > Hi: > > To amplify Ista's and David's comments: > > (1) You should not be inputting separate vectors into lm(), especially if > you intend to do prediction. They should be combined into a data frame > instead. This is not a requirement, but it's a much safer strategy for > modeling in R. > (2) Your covariate st does not have a linear component. It should, > particularly if this is an empirical model rather than a theoretical one. > (3) You should be using poly(var, 2) to create orthogonal columns in the > model matrix for the variables that are to contain quadratic terms. > (4) The newdata = argument of predict.lm() [whose help page you should read > carefully] requires a data frame with columns having precisely the same > variable names as exist in the RHS of the model formula in lm(). > > Example: > dd <- data.frame(y = rnorm(50), x1 = rnorm(50), x2 = runif(50, -2, 2), x3 = > rpois(50, 10)) > > # fit yhat = b0 + b1 * x1 + b2 * x1^2 + b3 * x2 + b4 * x3 + b5 * x3^2 > mod <- lm(y ~ poly(x1, 2) + x2 + poly(x3, 2), data = dd) > > # Note that the names of the variables in newd are the same as those on the > RHS of the formula in mod > newd <- data.frame(x1 = rnorm(5), x2 = runif(5, -2, 2), x3 = rpois(5, > 10)) # new data points > # Append predictions to newd > cbind(newd, predict(mod, newdata = newd)) # predictions at new > data points > > # To just get predictions at the observed points, all you need is > predict(mod) > > HTH, > Dennis > > On Sun, Mar 20, 2011 at 11:54 AM, Anna Lee wrote: >> >> Hey List, >> >> I did a multiple regression and my final model looks as follows: >> >> model9<-lm(calP ~ nsP + I(st^2) + distPr + I(distPr^2)) >> >> Now I tried to predict the values for calP from this model using the >> following function: >> >> xv<-seq(0,89,by=1) >> yv<-predict(model9,list(distPr=xv,st=xv,nsP=xv)) >> >> The predicted values are however strange. Now I do not know weather >> just the model does not fit the data (actually all coefficiets are >> significant and the plot(model) shows a good shape) or wether I did >> something wrong with my prediction command. Does anyone have an >> idea??? >> >> -- >> >> >> Thanks a lot, Anna >> >> __ >> 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. > > -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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] statistical question
Dear List! I want to compare medians of non normal distributed data. Is it possible and usefull to calculate 95% confidence intervals for medians? And if so - how can this be achieved in R? Thanks a lot! Anna -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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] another statistical question
Dear List! I have a unverse (basic population) which is not normally distributed. Now from this universe I take some subsets. Each subset is normally distributed within itself. I now want to compare the subsets and see if they differ significantly. So what is my assumption - normal distributed data and therefore comparison of means, or non normal distributed data and therefore comparison of medians? Cheers, Anna -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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] generate random numbers
Hey List, does anyone know how I can generate a vector of random numbers from a given distribution? Something like "rnorm" just for non normal distributions??? Thanks a lot! Anna -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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] Interpreting parameters of sigmoid fct
Dear list, I'm trying to fit a chapman-richards equation to my data, only I cannot interpret the parameters a, b and d. I know that the parameter b denotes the asymptote, but for the others I couldn't figure out. But I do need to know this in order to set my starting values. Here's the model: modPoplar<- nls(Diameter ~ d*(1-exp(-b *Age))^a ,start=list(a=20,b=0.9,d=33)) I attached the graph, too. Hoping for your answers! Best, Anna -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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] Fwd: Interpreting parameters of sigmoid fct
Dear list, I'm trying to fit a chapman-richards equation to my data, only I cannot interpret the parameters a, b and d. I know that the parameter b denotes the asymptote, but for the others I couldn't figure out. But I do need to know this in order to set my starting values. Here's the model: modPoplar<- nls(Diameter ~ d*(1-exp(-b *Age))^a ,start=list(a=20,b=0.9,d=33)) I attached the graph, too. Hoping for your answers! Best, Anna -- Telefon: 01577-7805329 E-Mail: gretschel.a...@googlemail.com __ 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] what characteristics of model curve do parameters denote
Dear list, I'm trying to fit a chapman-richards equation to my data, only I cannot interpret the parameters a, b and d. I know that the parameter b denotes the asymptote, but for the others I couldn't figure out. But I do need to know this in order to set my starting values. Here's the model: modPoplar<- nls(Diameter ~ d*(1-exp(-b *Age))^a ,start=list(a=20,b=0.9,d=33)) I attached the graph, too. Hoping for your answers! Best, Anna -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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] converting commas to points
Hello everyone! I work with a german excell version which uses commas instead of points for seperating decimal places. R work with points so in order to be able to save my excell tables without changing the commas to points, whenever I load a table I type in: read.table(..., dec = ",") only R puts the points into the wron places. For excample excell has a cell with the number: 0,09 so what R does, it writes the number as 0.9 which is wrong and makes my calculations become useless. Does anyone know this problem? Maby I made a mistake somewhere? I would be glad about your answers! Cheers, Anna -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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.
Re: [R] converting commas to points
Sorry guys, I allready found the solution. Excell showed some of the numbers in the format: 1,90053-E05 and R interpreted it as 1.9... I changed that in Excel Cheers, Anna Am 6. Oktober 2011 17:48 schrieb Uwe Ligges : > > > On 06.10.2011 17:39, Anna Lee wrote: >> >> Hello everyone! >> >> I work with a german excell version which uses commas instead of >> points for seperating decimal places. R work with points so in order >> to be able to save my excell tables without changing the commas to >> points, whenever I load a table I type in: read.table(..., dec = ",") >> only R puts the points into the wron places. For excample excell has a >> cell with the number: 0,09 so what R does, it writes the number as 0.9 > > Please specify an example with the excel output and what R reads. You will > find that such an example does not exist and hence you made some mistake and > compared different numbers or so. > > Uwe Ligges > > >> which is wrong and makes my calculations become useless. >> >> Does anyone know this problem? Maby I made a mistake somewhere? >> >> I would be glad about your answers! >> >> Cheers, Anna >> > -- Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu benachrichtigen und die E-Mail zu löschen. This e-mail is confidential. If you have received it in error, please notify me immediately and delete it from your system. __ 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.