0:20

Displacement I guess and horsepower are the predictors, okay?

Â And I'm going to use rgl.

Â You need to have rgl installed.

Â You have to do this locally.

Â You can't be using, for example, r studio on a web server to do this

Â because you need, rgl uses your graphics acceleration from your

Â 0:43

graphics card installed on your computer so can't really do it in the browser.

Â So you need to be running a local version of R to do this sort of stuff, okay.

Â Or if you're doing it externally, let say on a server,

Â you need to tunnel the X connection or something like that.

Â Okay, so let's open up a 3D window in rgl.

Â Okay, there it is, oops, that big.

Â 1:11

Resize a little bit, there you go.

Â Okay, and then I want to plot an ellipsoid of the fit,

Â and it turns out that the function, eclipse 3D can just take in

Â the fitted object by itself, and

Â it automatically just takes the first three coefficients, and

Â fits a simultaneous confidence ellipsoid for those three coefficients.

Â In this case, we only have three coefficients, so that's fine.

Â And I'm going to tell it I want color to be red.

Â The blending, this is not the type one error rate alpha,

Â this is the alpha blending for how transparent you want the object to be.

Â In this case I want it to be about 50% transparent.

Â I want aspect to equal true, that just means how it's going to

Â rescale the axis so I put it in and there it is, okay?

Â So this is now our confidence ellipsoid where displacement

Â is on one axis, the intercept is on the other axis and

Â the horsepower is on the third axis, okay?

Â So this is a three dimensional confidence ellipsoid for

Â those three coefficients simultaneously.

Â So the probability that the three dimensional point for beta one,

Â beta naught, beta one, and beta two lies in this confidence region is 95%,

Â under our assumptions, okay?

Â So now we can do this directly.

Â I think we should, given our discussion where we actually went through

Â the definition of an ellipse we should actually do it a little bit more directly.

Â So data is now just going to be coefficients from the fitted values.

Â Let me just show you what the data's are.

Â There's the betas.

Â 30 for the intercept minus 0.03 for displacement, and

Â minus 0.24 for horsepower.

Â And then, my sigma is just going to be the variance,

Â covariance, of the fitted matrix.

Â So sigma is the variance covariance matrix of the beta matrix.

Â So there it is 1.77, you can see it.

Â Okay, and then N is the number of rows and

Â E is the number of columns of X.

Â So in this case it turns out that the specific way the ellipse 3D needs it,

Â is it needs the A matrix to be sigma times the relevant F quantile.

Â And then three here is from the three dimensions, it's from

Â 3:41

the rank of the test, okay?

Â So that is there and I'm really being a little bit inaccurate because

Â this is really a inverse from the notation we were using in the last lecture.

Â So keep that in mind.

Â It took me a little bit of nitpicking to figure this out.

Â Okay, and then if you want the names to show up you need a vector of the names.

Â Okay, so let's open up the 3D connection.

Â 4:06

Okay, there that is.

Â And then, here we're going to do plot3d, so it takes ellipse3d,

Â and then it's taking A, but I think in our definition is is really A inverse.

Â It should be A inverse, okay?

Â And then you want it centered at my beta estimates, okay?

Â And in this case, my k is the identity matrix.

Â And then t equal 1 is just saying, define the ellipse as the set of points where

Â 4:36

the ellipse is less than or equal to 1.

Â This time, I want it to be blue.

Â And then I want alpha blending to be 0.5 so I want it to

Â be about 50% transparent, so it rescales the axisis to look nice to be true.

Â And then this is just setting my label names.

Â And then I do that, put it up, okay?

Â And then there it is.

Â You can see it's the same plot.

Â But now we've directly used the definition of an ellipse rather than relying

Â on ellipse3D to do the it for us.

Â So that's all that it is and hopefully now you can use this to

Â 5:14

do your own three dimensional confidence ellipsoid and hopefully you can also find

Â another eclipse plotting program to do two dimensional ones if you wanted to.

Â But this is, I think, a pretty nice way to visualize a three dimensional fit.

Â I think the way that I would most likely use a three dimensional

Â hyperellipse in order to visualize a confident set would be in the case where

Â I wanted to predict three things, and I wanted to see the simultaneous prediction.

Â I think that would be the most likely instance where I would use

Â some function like this, okay?

Â But it's pretty neat, you can impress your friends by using RGL to create

Â