View source: R/plot_effects_individual.R
plot_effects_individual | R Documentation |
plot_effects_individual
plot_effects_individual(
data,
pred_name,
resp_name,
predict_funct,
col.by = NULL,
npoints = 10,
center_effs = TRUE,
plot_obs = TRUE
)
data |
a data.frame |
pred_name |
character. name of the predictor (x) |
resp_name |
character. name of the response (y) |
predict_funct |
a function that makes predictions |
col.by |
NULL or a vector of values that indicate the strata |
npoints |
10 |
center_effs |
logical. Should be the effect of the oder predictors removed from the lines and the observations? |
plot_obs |
if TRUE (default) it draws the observed values (points) after residualization by the other predictors |
livio finos
n=100
X=matrix(rnorm(n*3),n,3)
X[,2]=sign(X[,2])
y=rnorm(n,X[,1]+X[,1]*X[,2])
D=data.frame(X)
D$y=y
# Regression model
mod=lm(y~X1*X2+X3,data=D)
summary(mod)
predict_funct=function(newdata) predict(mod,newdata=newdata)
plot_effects_individual(D,"X1","y",predict_funct=predict_funct)
plot_effects_individual(D,"X1","y",predict_funct=predict_funct,col.by = D$X2)
plot_effects_individual(D,"X3","y",predict_funct=predict_funct,center_effs = TRUE)
plot_effects_individual(D,"X3","y",predict_funct=predict_funct,center_effs = FALSE)
# Regression tree model
## Not run:
require(rpart)
mod=rpart(y~X1+X2+X3,data=D,control = list(cp=.0001))
print(mod)
printcp(mod)
predict_funct=function(newdata) predict(mod,newdata=newdata)
#plot_effects_individual(D,"X1","y",predict_funct=predict_funct)
plot_effects_individual(D,"X1","y",predict_funct=predict_funct,col.by = D$X2)
# compare the two:
plot_effects_individual(D,"X3","y",predict_funct=predict_funct,center_effs = TRUE)
plot_effects_individual(D,"X3","y",predict_funct=predict_funct,center_effs = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.