Fit3d: 3D plots of fitted response surfaces and functions

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Fit3d.R

Description

For the current plot, created with Plot3d, you can use Fit3d to superimpose the fitted response surface for one or more models. For example, following

Plot3d( y ~ x + z | g, data)

the fitted surface for a model fit with lm can be displayed with

Fit3d ( lm( y ~ x*z + I(x^2) + I(z^2) + g, data ))

Other forms are possible, as described under Details.

Usage

1
2
3
4
5
Fit3d(fit, names.vars = pars$names, other.vars = NULL, 
	grid.lines = 26, col = "blue", 
	fill = TRUE, grid = TRUE, base.grid = FALSE, col.grid = col, col.res = col, 
	residuals = FALSE, xlim = c(bbox[1], bbox[2]), zlim = c(bbox[5], bbox[6]), 
	verbose = 0, type = "response", alpha = 0.5, lit = FALSE, FUN = function(x) x, ...)

Arguments

fit

A fitted model object (e.g., of class lm, glm or lme ) involving two quantitative covariates and possibly other variables, or a function of two continuous variables and possibly other variables

names.vars
other.vars

list of values for variables used in model but not in display

grid.lines

Number of grid lines for x and z variables

col

The color used for the grid of fitted values and other annotations unless specified with other col.* arguments.

fill

Draw fitted or function values as a shaded surface? Default: TRUE

grid

Draw fitted or function values as a grid with lines? Default: TRUE

base.grid

draw grid in base horizontal plane? Default: FALSE

col.grid

Color used to draw the grid if grid=TRUE

col.res

Color used to show residuals if residuals=TRUE

residuals

Show residuals in the plot (i.e., lines from the surface to the points)?

xlim

Limits for the x variable, to override those in the current plot

zlim

Limits for the y variable, to override those in the current plot

verbose

Tell me what you're doing

type

For models fit with glm, fitted values can be displayed on the type="response" scale or the type="link" scale.

alpha

Transparency value for the fitted surface

lit

rgl lighting. See ...

FUN

The response for a model can be a transformation of the scale of the plot. The FUN argument is used to transform the fitted value back to the scale of the graph, e.g.

fit <- lm( log(y) ~ x * g, data); Fit3d( fit, FUN = exp)

...

Other arguments passed down

Details

Details: TBW

Value

No useful value, unless verbose=TRUE, in which case summary(fit) is returned.

Author(s)

Georges Monette

See Also

Plot3d

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Not run: 
 library(car)
 data(Prestige)
 Prestige$inc <- Prestige$income / 1000
 open3d()
 Plot3d ( inc ~ women + education|type , Prestige)
 
 Fit3d ( lm(inc ~ women + education,Prestige))
 Fit3d ( lm(inc ~ women * education,Prestige), col="pink")

## End(Not run)

data(coffee)
# fit marginal and joint models
fit.stress <- lm(Heart ~ Stress, data=coffee)
fit.coffee <- lm(Heart ~ Coffee, data=coffee)
fit.both   <- lm(Heart ~ Coffee + Stress, data=coffee)

Init3d(cex=1.2)
Plot3d( Heart ~ Coffee + Stress, coffee,
	surface=TRUE, fit="linear", surface.col="lightblue", 
	grid.lines=10, sphere.size=0.6)
box3d(color="gray")

data.Ell3d(col="lightblue")
# bivariate marginal ellipses
Lines3d( y = 'min', xz = with( coffee, dell( Coffee, Stress)), lwd=2, color="black")
Lines3d( z = 'min', xy = with( coffee, dell( Coffee, Heart)), lwd=2, color="blue")
Lines3d( x = 'min', yz = with( coffee, dell( Heart, Stress)), lwd=2, color="blue")
# fitted marginal regression planes
Fit3d(fit.stress, col="pink")
Fit3d(fit.coffee, col="green")

p3d documentation built on May 2, 2019, 5:25 p.m.