plot_response: Curve or surfaces of the expected reponse agaist the...

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

View source: R/utils.R

Description

This function plots the curve or the surfaces of the expected reponse agaist the corresponding variable (and the transition variable if surface).

Usage

1
plot_response(obj, vars, log_scale = FALSE, length.out = 20)

Arguments

obj

an object of the class PSTR returned from some functions in the package. Note that the corresponding PSTR model must be estimated first.

vars

a vector of column numbers or names (character strings) specifying which variables in the nonlinear part to use.

log_scale

a 2-dim vector or scalar specifying whether to take log scale for the variables and the transition variable.

length.out

a 2-dim vector or scalar of desired length (number of points) for the parameters. 20 by default.

Details

The expected response is the expected value of the dependent variable minus the individual effect and all the other variables times their estimated coefficients. That is, if the variable is z_{k,it} in both x_{it} and z_{it}, then the function plots the surface of

y_{it} - μ_i - β_{-k,0}' x_{-k,it} + β_{-k,1}' z_{-k,it} g_{it} - u_{it}

or simply

(β_{k,0} + β_{k,1}g_{it}) \cdot z_{k,it}

where -k means with the kth element removed, against z_{k,it} and q_{it} if z_{k,it} \neq q_{it}.

If z_{k,it} = q_{it}, then the function plots the curve of the expected response defined above against z_{k,it}.

More than one variable can be put in vars. If vars contains the transition variable and the transition variable belongs to the nonlinear part, the function will plot a curve of the effect-adjusted expected response and the transition variable, otherwise, the function will plot a 3-D surface of the effect-adjusted expected response against a chosen variable in the nonlinear part and the transition variable.

length.out takes a vector or a scalar. The vector must be two dimensional specifying numbers of points in the grid built for the surface. The first element of the vector corresponds to the variables, and the second to the transition variable. If it is a scalar, then grid has the same number of points for the variables and the transition varible.

The return value is a list of the same length as vars, whose elements are plottable objects.

Value

A list of plottable objects from the ggplot2 (for curve) and/or plotly (for surface) package.

Author(s)

Yukai Yang, yukai.yang@statistik.uu.se

See Also

Functions which return an object of the class PSTR and can be input into this function

EstPSTR

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
pstr = NewPSTR(Hansen99, dep='inva', indep=4:20, indep_k=c('vala','debta','cfa','sales'),
    tvars=c('vala','debta','cfa','sales'), iT=14) # create a new PSTR object

# estimate the PSTR model first
pstr = EstPSTR(use=pstr, im=1, iq=1, useDelta=TRUE, par=c(1.6,.5), method='CG')

# plot the curve and surfaces
ret = plot_response(obj=pstr, vars=1:4, log_scale = c(F,T), length.out=40)
attributes(ret)
ret$vala
ret$debta

lxylky1688/PSTRM documentation built on May 19, 2019, 1:47 a.m.