R: Predictions for Factor-Numeric Interactions in Linear Models
intQualQuant
R Documentation
Predictions for Factor-Numeric Interactions in Linear Models
Description
This function works on linear models with a single interaction between a continuous (numeric) variable and a factor. The output is a data frame that gives the predicted effect of moving from each category to each other category of the factor over the range of values of the continuous conditioning variable.
A vector of two variable names giving the two quantitative variables involved in the interaction. These variables must be involved in one, and only one, interaction.
level
Confidence level desired for lower and upper bounds of confidence interval.
labs
An optional vector of labels that will be used to identify the effects, if NULL, the factor levels will be used.
n
Number of values of the conditioning variable to use.
onlySig
Logical indicating whether only contrasts with significant differences should be returned. Significance is determined to exist if the largest lower bound is greater than zero or the smallest upper bound is smaller than zero.
type
String indicating whether the conditional partial effect of the factors is plotted (if ‘facs’), or the conditional partial effect of the quantitative variable (if ‘slopes’) is produced.
plot
Logical indicating whether graphical results (if TRUE) or numerical results (if FALSE) are produced.
vals
A vector of values at which the continuous variable will be held constant. If NULL, a sequence of length n across the variable's range will be used.
rug
Logical indicating whether rug plots should be plotted in the panels.
ci
Logical indicating whether confidence bounds should be drawn.
...
Other arguments to be passed down to effect if plot.type = ‘slopes’.
Value
For type = ‘facs’ and plot = FALSE, a data frame with the following values:
fit
The expected difference between the two factor levels at the specified value of the conditioning variable.
se.fit
The standard error of the expected differences.
x
The value of the continuous conditioning variable
contrast
A factor giving the two values of the factor being evaluated.
lower
The lower 95% confidence interval for fit
upper
The upper 95% confidence interval for fit
For type = ‘facs’ and plot = TRUE, a lattice display is returned
For type = ‘slopes’ and plot = FALSE, A character matrix with the following columns:
B
The conditional effect of the quantitative variable for each level of the factor.
SE(B)
The standard error of the conditional effect.
t-stat
The t-statistic of the conditional effect.
Pr(>|t|)
The two-sided p-value.
For type = ‘slopes’ and plot = TRUE, a lattice display is returned
Author(s)
Dave Armstrong (UW-Milwaukee, Department of Political Science)
Examples
library(car)
data(Prestige)
Prestige$income <- Prestige$income/1000
mod <- lm(prestige ~ income * type + education, data=Prestige)
intQualQuant(mod, c("income", "type"), n=10,
plot.type="none")
intQualQuant(mod, c("income", "type"), n=10,
plot.type="facs")
intQualQuant(mod, c("income", "type"), n=10,
plot.type="slopes")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(DAMisc)
Loading required package: car
Loading required package: effects
Attaching package: 'effects'
The following object is masked from 'package:car':
Prestige
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DAMisc/intQualQuant.Rd_%03d_medium.png", width=480, height=480)
> ### Name: intQualQuant
> ### Title: Predictions for Factor-Numeric Interactions in Linear Models
> ### Aliases: intQualQuant
>
> ### ** Examples
>
> library(car)
> data(Prestige)
> Prestige$income <- Prestige$income/1000
> mod <- lm(prestige ~ income * type + education, data=Prestige)
> intQualQuant(mod, c("income", "type"), n=10,
+ plot.type="none")
> intQualQuant(mod, c("income", "type"), n=10,
+ plot.type="facs")
> intQualQuant(mod, c("income", "type"), n=10,
+ plot.type="slopes")
>
>
>
>
>
> dev.off()
null device
1
>