Description Usage Arguments Details Value Author(s) References See Also Examples
margins
calculates the marginal effects of the variables given the result of regressions (madlib.lm
, madlib.glm
etc). Vars
lists all the variables used in the regression model. Terms
lists the specified terms in the original model. Vars
and Terms
are only used in margins
's dydx
option.
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 | ## S3 method for class 'lm.madlib'
margins(model, dydx = ~Vars(model), newdata =
model$data, at.mean = FALSE, factor.continuous = FALSE, na.action =
NULL, ...)
## S3 method for class 'lm.madlib.grps'
margins(model, dydx = ~Vars(model), newdata =
lapply(model, function(x) x$data), at.mean = FALSE, factor.continuous =
FALSE, na.action = NULL, ...)
## S3 method for class 'logregr.madlib'
margins(model, dydx = ~Vars(model), newdata =
model$data, at.mean = FALSE, factor.continuous = FALSE, na.action =
NULL, ...)
## S3 method for class 'logregr.madlib.grps'
margins(model, dydx = ~Vars(model),
newdata = lapply(model, function(x) x$data), at.mean = FALSE,
factor.continuous = FALSE, na.action = NULL, ...)
## S3 method for class 'margins'
print(x, digits = max(3L, getOption("digits") - 3L),
...)
Vars(model)
Terms(term = NULL)
|
model |
The result of |
dydx |
A formula, and the default is |
newdata |
A |
at.mean |
A logical, the default is |
factor.continuous |
A logical, the default is |
na.action |
A string which indicates what should happen when the data
contain |
... |
Other arguments, not implemented. |
x |
The result of |
digits |
A non-null value for ‘digits’ specifies the minimum number of
significant digits to be printed in values. The default,
‘NULL’, uses ‘getOption("digits")’. (For the interpretation
for complex numbers see |
term |
A vector of integers, the default is |
For a continuous variable, its marginal effects is just the first derivative of the response function with respect to the variable. For a categorical variable, it is usually more meaningful to compute the finite difference of the response function for the variable being 1 and 0. The finite difference marginal effect measures how much more the response function would be compared with the reference category. The reference category for a categorical variable can be changed by relevel
.
margins
function returns a margins
object, which is a data.frame
. It contains the following item:
Estimate |
The marginal effect values for all variable that have been specified in |
Std. Error |
The standard errors for the marginal effects. |
t value, z value |
The t statistics (for linear regression) or z statistics (for logistic regression). |
Pr(>|t|), Pr(>|z|) |
The corresponding p values. |
Vars
returns a vector of strings, which are the variable names that have been used in the regression model.
Author: Predictive Analytics Team at Pivotal Inc.
Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io
[1] Stata 13 help for margins, https://www.stata.com/help.cgi?margins
relevel
changes the reference category.
madlib.lm
, madlib.glm
compute linear and logistic regressions.
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 33 34 35 36 | ## Not run:
## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname)
## create a data table in database and the R wrapper
delete("abalone", conn.id = cid)
dat <- as.db.data.frame(abalone, "abalone", conn.id = cid)
fit <- madlib.lm(rings ~ length + diameter*sex, data = dat)
margins(fit)
margins(fit, at.mean = TRUE)
margins(fit, factor.continuous = TRUE)
margins(fit, dydx = ~ Vars(model) + Terms())
fit <- madlib.glm(rings < 10 ~ length + diameter*sex, data = dat, family = "logistic")
margins(fit, ~ length + sex)
margins(fit, ~ length + sex.M, at.mean = TRUE)
margins(fit, ~ length + sex.I, factor.continuous = TRUE)
margins(fit, ~ Vars(model) + Terms())
## create a data table that has two columns
## one of them is an array column
dat1 <- cbind(db.array(dat[,-c(1,2,10)]), dat[,10])
names(dat1) <- c("x", "y")
delete("abalone_array", conn.id = cid)
dat1 <- as.db.data.frame(dat1, "abalone_array")
fit <- madlib.glm(y < 10 ~ x[-1], data = dat1, family = "logistic")
margins(fit, ~ x[2:5])
db.disconnect(cid, verbose = FALSE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.