Exercise

# Models in 3D

An alternative way to visualize a multiple regression model with two numeric explanatory variables is as a plane in three dimensions. This is possible in R using the `plotly`

package.

We have created three objects that you will need:

`x`

: a vector of unique values of`duration`

`y`

: a vector of unique values of`startPr`

`plane`

: a matrix of the fitted values across all combinations of`x`

and`y`

Much like `ggplot()`

, the `plot_ly()`

function will allow you to create a plot object with variables mapped to `x`

, `y`

, and `z`

aesthetics. The `add_markers()`

function is similar to `geom_point()`

in that it allows you to add points to your 3D plot.

Note that `plot_ly`

uses the pipe (`%>%`

) operator to chain commands together.

Instructions

**100 XP**

- Run the
`plot_ly`

command to draw 3D scatterplot for`totalPr`

as a function of`duration`

and`startPr`

by mapping the`z`

variable to the response and the`x`

and`y`

variables to the explanatory variables. Duration should be on the x-axis and starting price should be on the y-axis. - Use
`add_surface()`

to draw a plane through the cloud of points by setting`z = ~plane`

.