Re: [R] confidence / prediction ellipse
Hi Giuseppe You've posted a series of questions on this topic, never with any code you've tried or data, and usually with some undefined references to 'a' and 'b'. In spite of this, a variety of people have tried to give you helpful replies, intuiting what it is you might have meant. This is wasteful of everyone's time. If you want help from R-help, please make your effort to formulate a precise question, preferably with code and data. Otherwise, you might post to R-mindreaders if it ever gets established. On 2/7/2013 11:20 AM, Giuseppe Amatulli wrote: Hi Rolf, sorry for this late answer and thanks for your kind explanation and relative R code. I really appreciate. In reality the concept that I'm trying to address is a bit more complex. I'm fitting a model y vs 6 predictors with MARS / RandomForest / Multiple Linear Regression Models having 140 observations. I have the prediction of each model and would like to delineate the prediction ellipses for 3 models, for the 95% probability, and plotting them together with the observation vs prediction. I think that the prediction-ellipses code that you provide to me is valid also for predictions derived by not-linear model (such as MARS and RF). Is it correct? or should i use an alternative solution ? Moreover, I was expecting that the abline (lm(b,a)) would be correspond to the main axis of the prediction ellipse, but is not this the case. why? Thanks in advance Giuseppe On 28 January 2013 19:04, Rolf Turner rolf.tur...@xtra.co.nz wrote: I believe that the value of radius that you are using is incorrect. If you have a data matrix X whose columns are jointly distributed N(mu,Sigma) then a confidence ellipse for mu is determined by n * (x - Xbar)' S^{-1}(x - Xbar) ~ T^2 where Xbar is the mean vector for X and S is the sample covariance matrix, and where T^2 means Hotelling's T-squared distribution, which is equal to (n-1)*2/(n-2) * F_{2,n-2} the latter representing the F distribution on 2 and n-2 degrees of freedom. Thus (I think) your radius should be radius - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) where npts - length(a). Note that it is qf(0.95,2,npts-2) and *NOT* qf(0.95,2,npts-1). To get the corresponding *prediction* ellipse simply multiply the foregoing radius by sqrt(npts+1). By prediction ellipse I mean an ellipse such that the probability that a new independent observation from the same population will fall in that ellipse is the given probability (e.g. 0.95). Note that this does not mean that 95% of the data will fall in the calculated ellipse (basically because of the *dependence* between S and the individual observations). These confidence and prediction ellipses are (I'm pretty sure) valid under the assumption that the data are (two dimensional, independent) Gaussian, and that you use the sample covariance and sample mean as shape and centre. I don't know what impact your robustification procedure of using cov.trob() will/would have on the properties of these ellipses. A script which does the ellipses for your toy data, using the sample covariance and sample mean (rather than output from cov.trob()) is as follows: # # Script scr.amatulli # require(car) a - c(12,12,4,5,63,63,23) b - c(13,15,7,10,73,83,43) npts - length(a) shape - var(cbind(a, b)) center - c(mean(a),mean(b)) rconf - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) rpred - sqrt(npts+1)*rconf conf.elip - ellipse(center, shape, rconf,draw = FALSE) pred.elip - ellipse(center, shape, rpred,draw = FALSE) plot(pred.elip, type='l') points(a,b) lines(conf.elip,col=red) cheers, Rolf Turner On 01/27/2013 10:12 AM, Giuseppe Amatulli wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ 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
Re: [R] confidence / prediction ellipse
On Feb 7, 2013, at 8:20 AM, Giuseppe Amatulli wrote: Hi Rolf, sorry for this late answer and thanks for your kind explanation and relative R code. I really appreciate. In reality the concept that I'm trying to address is a bit more complex. I'm fitting a model y vs 6 predictors with MARS / RandomForest / Multiple Linear Regression Models having 140 observations. I have the prediction of each model and would like to delineate the prediction ellipses for 3 models, for the 95% probability, and plotting them together with the observation vs prediction. I think that the prediction-ellipses code that you provide to me is valid also for predictions derived by not-linear model (such as MARS and RF). Is it correct? or should i use an alternative solution ? Well, if a method provides a probability estimate or even if it only provides a rankable order, could always use color change to highlight the the most predicted 95%. I say most predicted rather than most probable, since it's not clear that these are probability or credibility estimates. Moreover, I was expecting that the abline (lm(b,a)) would be correspond to the main axis of the prediction ellipse, but is not this the case. why? Presumably you meant lm(b~a)? You might have also expected ( ... also incorrectly) that the line for lm(a~b) would be along the major axis. Perhaps reading some material on orthogonal regression (AKA total least squares regression, AKA Deming regression) would be of interest. The major axis should split the difference between those two estimates. -- David Thanks in advance Giuseppe On 28 January 2013 19:04, Rolf Turner rolf.tur...@xtra.co.nz wrote: I believe that the value of radius that you are using is incorrect. If you have a data matrix X whose columns are jointly distributed N(mu,Sigma) then a confidence ellipse for mu is determined by n * (x - Xbar)' S^{-1}(x - Xbar) ~ T^2 where Xbar is the mean vector for X and S is the sample covariance matrix, and where T^2 means Hotelling's T-squared distribution, which is equal to (n-1)*2/(n-2) * F_{2,n-2} the latter representing the F distribution on 2 and n-2 degrees of freedom. Thus (I think) your radius should be radius - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) where npts - length(a). Note that it is qf(0.95,2,npts-2) and *NOT* qf(0.95,2,npts-1). To get the corresponding *prediction* ellipse simply multiply the foregoing radius by sqrt(npts+1). By prediction ellipse I mean an ellipse such that the probability that a new independent observation from the same population will fall in that ellipse is the given probability (e.g. 0.95). Note that this does not mean that 95% of the data will fall in the calculated ellipse (basically because of the *dependence* between S and the individual observations). These confidence and prediction ellipses are (I'm pretty sure) valid under the assumption that the data are (two dimensional, independent) Gaussian, and that you use the sample covariance and sample mean as shape and centre. I don't know what impact your robustification procedure of using cov.trob() will/would have on the properties of these ellipses. A script which does the ellipses for your toy data, using the sample covariance and sample mean (rather than output from cov.trob()) is as follows: # # Script scr.amatulli # require(car) a - c(12,12,4,5,63,63,23) b - c(13,15,7,10,73,83,43) npts - length(a) shape - var(cbind(a, b)) center - c(mean(a),mean(b)) rconf - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) rpred - sqrt(npts+1)*rconf conf.elip - ellipse(center, shape, rconf,draw = FALSE) pred.elip - ellipse(center, shape, rpred,draw = FALSE) plot(pred.elip, type='l') points(a,b) lines(conf.elip,col=red) cheers, Rolf Turner On 01/27/2013 10:12 AM, Giuseppe Amatulli wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] confidence / prediction ellipse
Hi Rolf, sorry for this late answer and thanks for your kind explanation and relative R code. I really appreciate. In reality the concept that I'm trying to address is a bit more complex. I'm fitting a model y vs 6 predictors with MARS / RandomForest / Multiple Linear Regression Models having 140 observations. I have the prediction of each model and would like to delineate the prediction ellipses for 3 models, for the 95% probability, and plotting them together with the observation vs prediction. I think that the prediction-ellipses code that you provide to me is valid also for predictions derived by not-linear model (such as MARS and RF). Is it correct? or should i use an alternative solution ? Moreover, I was expecting that the abline (lm(b,a)) would be correspond to the main axis of the prediction ellipse, but is not this the case. why? Thanks in advance Giuseppe On 28 January 2013 19:04, Rolf Turner rolf.tur...@xtra.co.nz wrote: I believe that the value of radius that you are using is incorrect. If you have a data matrix X whose columns are jointly distributed N(mu,Sigma) then a confidence ellipse for mu is determined by n * (x - Xbar)' S^{-1}(x - Xbar) ~ T^2 where Xbar is the mean vector for X and S is the sample covariance matrix, and where T^2 means Hotelling's T-squared distribution, which is equal to (n-1)*2/(n-2) * F_{2,n-2} the latter representing the F distribution on 2 and n-2 degrees of freedom. Thus (I think) your radius should be radius - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) where npts - length(a). Note that it is qf(0.95,2,npts-2) and *NOT* qf(0.95,2,npts-1). To get the corresponding *prediction* ellipse simply multiply the foregoing radius by sqrt(npts+1). By prediction ellipse I mean an ellipse such that the probability that a new independent observation from the same population will fall in that ellipse is the given probability (e.g. 0.95). Note that this does not mean that 95% of the data will fall in the calculated ellipse (basically because of the *dependence* between S and the individual observations). These confidence and prediction ellipses are (I'm pretty sure) valid under the assumption that the data are (two dimensional, independent) Gaussian, and that you use the sample covariance and sample mean as shape and centre. I don't know what impact your robustification procedure of using cov.trob() will/would have on the properties of these ellipses. A script which does the ellipses for your toy data, using the sample covariance and sample mean (rather than output from cov.trob()) is as follows: # # Script scr.amatulli # require(car) a - c(12,12,4,5,63,63,23) b - c(13,15,7,10,73,83,43) npts - length(a) shape - var(cbind(a, b)) center - c(mean(a),mean(b)) rconf - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) rpred - sqrt(npts+1)*rconf conf.elip - ellipse(center, shape, rconf,draw = FALSE) pred.elip - ellipse(center, shape, rpred,draw = FALSE) plot(pred.elip, type='l') points(a,b) lines(conf.elip,col=red) cheers, Rolf Turner On 01/27/2013 10:12 AM, Giuseppe Amatulli wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net __ 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] confidence / prediction ellipse
Please see in-line below. On 02/08/2013 05:20 AM, Giuseppe Amatulli wrote: Hi Rolf, sorry for this late answer and thanks for your kind explanation and relative R code. I really appreciate. In reality the concept that I'm trying to address is a bit more complex. I'm fitting a model y vs 6 predictors with MARS / RandomForest / Multiple Linear Regression Models having 140 observations. I have the prediction of each model and would like to delineate the prediction ellipses for 3 models, for the 95% probability, and plotting them together with the observation vs prediction. I think that the prediction-ellipses code that you provide to me is valid also for predictions derived by not-linear model (such as MARS and RF). Is it correct? Probably not. The degrees of freedom will very likely be wrong. You need to consult a suitable book on multivariate analysis --- quite possibly Seber's book Multivariate Observations would help. or should i use an alternative solution ? At the very least some adjustment will be required I think. Moreover, I was expecting that the abline (lm(b,a)) would be correspond to the main axis of the prediction ellipse, Why do you expect that? but is not this the case. why? No idea. What are b and a? In general if a and b are jointly Gaussian you can (i) regress b on a and plot the fitted regression line, which is what abline(lm(b~a)) will do, or (ii) form the prediction ellipse for (a,b) . The major axis of this prediction ellipse will NOT be the regression line. I have a vague recollection that this major axis is the line which minimizes the sum of squares of the *orthogonal* distances of the points to the line (whereas the regression line minimizes the sum of squares of the *vertical* distances). But none of this seems to me to have much if anything to do with what you are trying to accomplish. At any rate this discussion has nothing to do with R. You should ask about it on some statistics discussion forum, or consult with an expert on multivariate statistics. cheers, Rolf Turner Thanks in advance Giuseppe On 28 January 2013 19:04, Rolf Turner rolf.tur...@xtra.co.nz wrote: I believe that the value of radius that you are using is incorrect. If you have a data matrix X whose columns are jointly distributed N(mu,Sigma) then a confidence ellipse for mu is determined by n * (x - Xbar)' S^{-1}(x - Xbar) ~ T^2 where Xbar is the mean vector for X and S is the sample covariance matrix, and where T^2 means Hotelling's T-squared distribution, which is equal to (n-1)*2/(n-2) * F_{2,n-2} the latter representing the F distribution on 2 and n-2 degrees of freedom. Thus (I think) your radius should be radius - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) where npts - length(a). Note that it is qf(0.95,2,npts-2) and *NOT* qf(0.95,2,npts-1). To get the corresponding *prediction* ellipse simply multiply the foregoing radius by sqrt(npts+1). By prediction ellipse I mean an ellipse such that the probability that a new independent observation from the same population will fall in that ellipse is the given probability (e.g. 0.95). Note that this does not mean that 95% of the data will fall in the calculated ellipse (basically because of the *dependence* between S and the individual observations). These confidence and prediction ellipses are (I'm pretty sure) valid under the assumption that the data are (two dimensional, independent) Gaussian, and that you use the sample covariance and sample mean as shape and centre. I don't know what impact your robustification procedure of using cov.trob() will/would have on the properties of these ellipses. A script which does the ellipses for your toy data, using the sample covariance and sample mean (rather than output from cov.trob()) is as follows: # # Script scr.amatulli # require(car) a - c(12,12,4,5,63,63,23) b - c(13,15,7,10,73,83,43) npts - length(a) shape - var(cbind(a, b)) center - c(mean(a),mean(b)) rconf - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) rpred - sqrt(npts+1)*rconf conf.elip - ellipse(center, shape, rconf,draw = FALSE) pred.elip - ellipse(center, shape, rpred,draw = FALSE) plot(pred.elip, type='l') points(a,b) lines(conf.elip,col=red) cheers, Rolf Turner On 01/27/2013 10:12 AM, Giuseppe Amatulli wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 *
Re: [R] confidence / prediction ellipse
I believe that the value of radius that you are using is incorrect. If you have a data matrix X whose columns are jointly distributed N(mu,Sigma) then a confidence ellipse for mu is determined by n * (x - Xbar)' S^{-1}(x - Xbar) ~ T^2 where Xbar is the mean vector for X and S is the sample covariance matrix, and where T^2 means Hotelling's T-squared distribution, which is equal to (n-1)*2/(n-2) * F_{2,n-2} the latter representing the F distribution on 2 and n-2 degrees of freedom. Thus (I think) your radius should be radius - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) where npts - length(a). Note that it is qf(0.95,2,npts-2) and *NOT* qf(0.95,2,npts-1). To get the corresponding *prediction* ellipse simply multiply the foregoing radius by sqrt(npts+1). By prediction ellipse I mean an ellipse such that the probability that a new independent observation from the same population will fall in that ellipse is the given probability (e.g. 0.95). Note that this does not mean that 95% of the data will fall in the calculated ellipse (basically because of the *dependence* between S and the individual observations). These confidence and prediction ellipses are (I'm pretty sure) valid under the assumption that the data are (two dimensional, independent) Gaussian, and that you use the sample covariance and sample mean as shape and centre. I don't know what impact your robustification procedure of using cov.trob() will/would have on the properties of these ellipses. A script which does the ellipses for your toy data, using the sample covariance and sample mean (rather than output from cov.trob()) is as follows: # # Script scr.amatulli # require(car) a - c(12,12,4,5,63,63,23) b - c(13,15,7,10,73,83,43) npts - length(a) shape - var(cbind(a, b)) center - c(mean(a),mean(b)) rconf - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2))) rpred - sqrt(npts+1)*rconf conf.elip - ellipse(center, shape, rconf,draw = FALSE) pred.elip - ellipse(center, shape, rpred,draw = FALSE) plot(pred.elip, type='l') points(a,b) lines(conf.elip,col=red) cheers, Rolf Turner On 01/27/2013 10:12 AM, Giuseppe Amatulli wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe __ 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] confidence / prediction ellipse
You appear to be quite confused. I have no idea what your a and b below mean. The SAS documentation that you quote is for prediction from a bivariate normal. I don't know what that has to do with your problem, nor with car's confidence ellipses for parameters for a univariate regression. I would suggest you get local statistical help, though perhaps someone with more time on their hands on this list than I may help sort you out. Cheers, Bert On Sun, Jan 27, 2013 at 8:41 AM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, thanks for your replay. My values of a and b are respectively: a = observation of an event b = prediction of a model. Therefore i would like to draw the confidence region for predicting a new observation, and according to this http://v8doc.sas.com/sashtml/insight/chap40/sect35.htm the prediction ellipse should be more appropriate. But i'm not able to track back the function radius - sqrt(dfn * qf(level, dfn, dfd)) in order to change it and draw a prediction ellipses. Regards Giuseppe On 26 January 2013 17:19, Bert Gunter gunter.ber...@gene.com wrote: Well, I'd guess you have to first define what you mean by prediction ellipse, as the confidence ellipses are for the bivariate distribution of 2 parameter estimates -- as I understand it -- whereas predictions depend on the covariate values and are for a single response value (unless you have fitted multiple responses, I suppose). -- Bert On Sat, Jan 26, 2013 at 1:12 PM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Giuseppe Amatulli Web: www.spatial-ecology.net -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] confidence / prediction ellipse
Hi, thanks for your replay. My values of a and b are respectively: a = observation of an event b = prediction of a model. Therefore i would like to draw the confidence region for predicting a new observation, and according to this http://v8doc.sas.com/sashtml/insight/chap40/sect35.htm the prediction ellipse should be more appropriate. But i'm not able to track back the function radius - sqrt(dfn * qf(level, dfn, dfd)) in order to change it and draw a prediction ellipses. Regards Giuseppe On 26 January 2013 17:19, Bert Gunter gunter.ber...@gene.com wrote: Well, I'd guess you have to first define what you mean by prediction ellipse, as the confidence ellipses are for the bivariate distribution of 2 parameter estimates -- as I understand it -- whereas predictions depend on the covariate values and are for a single response value (unless you have fitted multiple responses, I suppose). -- Bert On Sat, Jan 26, 2013 at 1:12 PM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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.
Re: [R] confidence / prediction ellipse
Dear Giuseppe and Bert, I also didn't follow what's intended, more or less for the same reasons as Bert mentioned, which is why I didn't reply to the initial posting. In the car package, confidenceEllipse() draws confidence ellipses for a pair of coefficients from a statistical model, and dataEllipse() draws bivariate-normal concentration ellipses for the bivariate distribution of two variables. I'm copying to Georges Monette and Michael Friendly, coauthors of these functions, in case they have something to add. I hope that this helps, but I doubt that it does. John --- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Giuseppe Amatulli Sent: Sunday, January 27, 2013 11:41 AM To: Bert Gunter Cc: r-help@r-project.org Subject: Re: [R] confidence / prediction ellipse Hi, thanks for your replay. My values of a and b are respectively: a = observation of an event b = prediction of a model. Therefore i would like to draw the confidence region for predicting a new observation, and according to this http://v8doc.sas.com/sashtml/insight/chap40/sect35.htm the prediction ellipse should be more appropriate. But i'm not able to track back the function radius - sqrt(dfn * qf(level, dfn, dfd)) in order to change it and draw a prediction ellipses. Regards Giuseppe On 26 January 2013 17:19, Bert Gunter gunter.ber...@gene.com wrote: Well, I'd guess you have to first define what you mean by prediction ellipse, as the confidence ellipses are for the bivariate distribution of 2 parameter estimates -- as I understand it -- whereas predictions depend on the covariate values and are for a single response value (unless you have fitted multiple responses, I suppose). -- Bert On Sat, Jan 26, 2013 at 1:12 PM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional- groups/pdb-biostatistics/pdb-ncb-home.htm -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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.
Re: [R] confidence / prediction ellipse
All: Aha! -- The light dawneth, methinks (maybe...) Giuseppe: I re-read the SAS link you sent and if I have parsed it correctly, what SAS chooses to call an ellipse for prediction -- a rather idiosyncratic way to describe it, imo -- I believe the rest of us would call a contour for a population quantile. The key phrase that indicates this is It [the elliptical region] also approximates a region containing a specified percentage of the population. So, if I'm right, I believe you just need to use car's data.ellipse() function. And if I'm wrong, my little corner of the globe remains cloaked in darkness confusion. Cheers, Bert On Sun, Jan 27, 2013 at 12:43 PM, John Fox j...@mcmaster.ca wrote: Dear Giuseppe and Bert, I also didn't follow what's intended, more or less for the same reasons as Bert mentioned, which is why I didn't reply to the initial posting. In the car package, confidenceEllipse() draws confidence ellipses for a pair of coefficients from a statistical model, and dataEllipse() draws bivariate-normal concentration ellipses for the bivariate distribution of two variables. I'm copying to Georges Monette and Michael Friendly, coauthors of these functions, in case they have something to add. I hope that this helps, but I doubt that it does. John --- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Giuseppe Amatulli Sent: Sunday, January 27, 2013 11:41 AM To: Bert Gunter Cc: r-help@r-project.org Subject: Re: [R] confidence / prediction ellipse Hi, thanks for your replay. My values of a and b are respectively: a = observation of an event b = prediction of a model. Therefore i would like to draw the confidence region for predicting a new observation, and according to this http://v8doc.sas.com/sashtml/insight/chap40/sect35.htm the prediction ellipse should be more appropriate. But i'm not able to track back the function radius - sqrt(dfn * qf(level, dfn, dfd)) in order to change it and draw a prediction ellipses. Regards Giuseppe On 26 January 2013 17:19, Bert Gunter gunter.ber...@gene.com wrote: Well, I'd guess you have to first define what you mean by prediction ellipse, as the confidence ellipses are for the bivariate distribution of 2 parameter estimates -- as I understand it -- whereas predictions depend on the covariate values and are for a single response value (unless you have fitted multiple responses, I suppose). -- Bert On Sat, Jan 26, 2013 at 1:12 PM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional- groups/pdb-biostatistics/pdb-ncb-home.htm -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read
Re: [R] confidence / prediction ellipse
Dear all, thanks for your input. Bert - yes you get the point, i would to like to draw an ellipse contour for a population quantile. Indeed, as you mention data.ellipse() should draw that. In other words if i re-run my model for another prediction (getting a new vector b) i would have the 95% probability that my prediction fall inside the ellipse. Thanks again Giuseppe On 27 January 2013 17:26, Bert Gunter gunter.ber...@gene.com wrote: All: Aha! -- The light dawneth, methinks (maybe...) Giuseppe: I re-read the SAS link you sent and if I have parsed it correctly, what SAS chooses to call an ellipse for prediction -- a rather idiosyncratic way to describe it, imo -- I believe the rest of us would call a contour for a population quantile. The key phrase that indicates this is It [the elliptical region] also approximates a region containing a specified percentage of the population. So, if I'm right, I believe you just need to use car's data.ellipse() function. And if I'm wrong, my little corner of the globe remains cloaked in darkness confusion. Cheers, Bert On Sun, Jan 27, 2013 at 12:43 PM, John Fox j...@mcmaster.ca wrote: Dear Giuseppe and Bert, I also didn't follow what's intended, more or less for the same reasons as Bert mentioned, which is why I didn't reply to the initial posting. In the car package, confidenceEllipse() draws confidence ellipses for a pair of coefficients from a statistical model, and dataEllipse() draws bivariate-normal concentration ellipses for the bivariate distribution of two variables. I'm copying to Georges Monette and Michael Friendly, coauthors of these functions, in case they have something to add. I hope that this helps, but I doubt that it does. John --- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Giuseppe Amatulli Sent: Sunday, January 27, 2013 11:41 AM To: Bert Gunter Cc: r-help@r-project.org Subject: Re: [R] confidence / prediction ellipse Hi, thanks for your replay. My values of a and b are respectively: a = observation of an event b = prediction of a model. Therefore i would like to draw the confidence region for predicting a new observation, and according to this http://v8doc.sas.com/sashtml/insight/chap40/sect35.htm the prediction ellipse should be more appropriate. But i'm not able to track back the function radius - sqrt(dfn * qf(level, dfn, dfd)) in order to change it and draw a prediction ellipses. Regards Giuseppe On 26 January 2013 17:19, Bert Gunter gunter.ber...@gene.com wrote: Well, I'd guess you have to first define what you mean by prediction ellipse, as the confidence ellipses are for the bivariate distribution of 2 parameter estimates -- as I understand it -- whereas predictions depend on the covariate values and are for a single response value (unless you have fitted multiple responses, I suppose). -- Bert On Sat, Jan 26, 2013 at 1:12 PM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional- groups/pdb-biostatistics/pdb-ncb-home.htm -- Giuseppe Amatulli Web: www.spatial-ecology.net [[alternative HTML version deleted
Re: [R] confidence / prediction ellipse
On Jan 27, 2013, at 8:16 PM, Giuseppe Amatulli wrote: Dear all, thanks for your input. Bert - yes you get the point, i would to like to draw an ellipse contour for a population quantile. Indeed, as you mention data.ellipse() should draw that. In other words if i re-run my model for another prediction (getting a new vector b) i would have the 95% probability that my prediction fall inside the ellipse. install.packages(hdrcde) # from Rob Hyndman require(hdrcde) x - c(rnorm(200,0,1),rnorm(200,4,1)) y - c(rnorm(200,0,1),rnorm(200,4,1)) par(mfrow=c(1,2)) plot(x,y, pch=+, cex=.5) hdr.boxplot.2d(x,y) -- David. On 27 January 2013 17:26, Bert Gunter gunter.ber...@gene.com wrote: All: Aha! -- The light dawneth, methinks (maybe...) Giuseppe: I re-read the SAS link you sent and if I have parsed it correctly, what SAS chooses to call an ellipse for prediction -- a rather idiosyncratic way to describe it, imo -- I believe the rest of us would call a contour for a population quantile. The key phrase that indicates this is It [the elliptical region] also approximates a region containing a specified percentage of the population. So, if I'm right, I believe you just need to use car's data.ellipse() function. And if I'm wrong, my little corner of the globe remains cloaked in darkness confusion. Cheers, Bert On Sun, Jan 27, 2013 at 12:43 PM, John Fox j...@mcmaster.ca wrote: Dear Giuseppe and Bert, I also didn't follow what's intended, more or less for the same reasons as Bert mentioned, which is why I didn't reply to the initial posting. In the car package, confidenceEllipse() draws confidence ellipses for a pair of coefficients from a statistical model, and dataEllipse() draws bivariate-normal concentration ellipses for the bivariate distribution of two variables. I'm copying to Georges Monette and Michael Friendly, coauthors of these functions, in case they have something to add. I hope that this helps, but I doubt that it does. John --- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Giuseppe Amatulli Sent: Sunday, January 27, 2013 11:41 AM To: Bert Gunter Cc: r-help@r-project.org Subject: Re: [R] confidence / prediction ellipse Hi, thanks for your replay. My values of a and b are respectively: a = observation of an event b = prediction of a model. Therefore i would like to draw the confidence region for predicting a new observation, and according to this http://v8doc.sas.com/sashtml/insight/chap40/sect35.htm the prediction ellipse should be more appropriate. But i'm not able to track back the function radius - sqrt(dfn * qf(level, dfn, dfd)) in order to change it and draw a prediction ellipses. Regards Giuseppe On 26 January 2013 17:19, Bert Gunter gunter.ber...@gene.com wrote: Well, I'd guess you have to first define what you mean by prediction ellipse, as the confidence ellipses are for the bivariate distribution of 2 parameter estimates -- as I understand it -- whereas predictions depend on the covariate values and are for a single response value (unless you have fitted multiple responses, I suppose). -- Bert On Sat, Jan 26, 2013 at 1:12 PM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional- groups/pdb-biostatistics/pdb-ncb-home.htm -- Giuseppe Amatulli Web: www.spatial-ecology.net [[alternative HTML version deleted]] __ R-help@r-project.org mailing
Re: [R] confidence / prediction ellipse
Well, I'd guess you have to first define what you mean by prediction ellipse, as the confidence ellipses are for the bivariate distribution of 2 parameter estimates -- as I understand it -- whereas predictions depend on the covariate values and are for a single response value (unless you have fitted multiple responses, I suppose). -- Bert On Sat, Jan 26, 2013 at 1:12 PM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v - cov.trob(cbind(a, b)) shape - v$cov center - v$center radius - sqrt(2 * qf(0.95, 2, length(a) - 1)) # radius - sqrt(dfn * qf(level, dfn, dfd)) conf.elip = ellipse(center, shape, radius,draw = F) plot(conf.elip, type='l') points(a,b) My question is how I can calculate shape, center and radius to obtain a prediction ellipses rather than a confidence ellipse? Thanks in Advance Giuseppe -- Giuseppe Amatulli Web: www.spatial-ecology.net [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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.