There seem to be two popular ways of calculating VIFs (Variance Inflation Factors, to detect collinearity among variables in regression) in R:
The vif() function in the car package, where the input is the model. This requires you to first fit a model before you can check for VIFs among variables in the model.
The corvif() function, where the input are the actual candidate explanatory variables (i.e. a list of variables, before the model is even fitted). This function is part of the AED package (Zuur et al. 2009), which has been discontinued. This one seems to work only on a list of variables, not on a fitted regression model.
Here is a data example:
MyData<-structure(list(site = structure(c(3L, 1L, 5L, 1L, 2L, 3L, 2L,
4L, 1L, 2L, 2L, 3L, 4L, 3L, 2L, 2L, 4L, 1L, 1L, 3L, 3L, 1L, 4L,
3L, 1L, 3L, 4L, 5L, 1L, 3L, 1L, 2L, 4L, 2L, 1L, 1L, 5L, 3L, 1L,
3L, 4L, 3L, 1L, 4L, 4L, 2L, 5L, 2L, 1L, 4L, 1L, 1L, 1L, 4L, 4L,
3L, 5L, 3L, 1L, 3L, 1L, 1L, 3L, 1L, 4L, 5L, 1L, 5L, 1L, 4L, 1L,
4L, 1L, 2L, 5L, 2L, 3L, 1L, 5L, 4L, 1L, 1L, 3L, 2L, 1L, 3L, 5L,
3L, 3L, 5L, 2L, 1L, 3L, 5L, 4L, 5L, 5L, 1L, 3L, 2L, 5L, 4L, 3L,
3L, 2L, 5L, 2L, 1L, 1L, 3L, 3L, 5L, 5L, 5L, 3L, 1L, 1L, 5L, 5L,
5L, 2L, 3L, 5L, 1L, 3L, 3L, 4L, 4L, 4L, 5L, 2L, 3L, 1L, 4L, 2L,
4L, 3L, 4L, 3L, 3L, 4L, 1L, 3L, 4L, 1L, 4L, 4L, 5L, 4L, 4L, 1L,
4L, 1L, 2L, 1L, 2L, 4L, 2L, 4L, 3L, 5L, 1L, 2L, 3L, 1L, 1L, 4L,
3L, 1L, 1L, 1L, 4L, 3L, 5L, 4L, 2L, 1L, 4L, 1L, 2L, 1L, 1L, 5L,
1L, 5L, 3L, 1L, 5L, 3L, 5L, 3L, 5L, 3L, 1L, 5L, 1L, 1L, 1L, 3L,
1L, 4L, 4L, 2L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60L, 45L, 60L, 410L, 50L, 40L, 210L, 140L, 120L, 70L,
35L, 30L, 90L, 40L, 240L, 40L, 55L, 120L, 200L, 65L, 40L,
95L, 140L, 220L, 70L, 40L, 30L, 50L, 95L, 50L, 50L, 50L,
70L, 160L, 45L, 35L, 50L, 70L, 230L, 110L, 300L, 50L, 105L,
60L, 50L, 60L, 70L, 30L, 60L, 30L, 110L, 80L, 80L, 30L, 60L,
70L, 80L, 60L, 40L, 220L, 140L, 110L, 40L, 40L, 40L, 90L,
125L, 90L, 100L, 270L, 420L, 60L, 70L, 53L, 40L, 80L, 90L,
30L, 40L, 65L, 40L, 110L, 90L, 40L, 190L, 110L, 70L, 52L,
120L, 95L, 50L, 50L, 140L, 75L, 30L, 50L, 60L, 125L, 60L,
80L, 35L, 55L, 140L, 140L, 240L, 65L, 40L, 200L, 80L, 60L,
65L, 120L, 80L, 230L, 150L, 40L, 50L, 60L, 210L, 50L, 130L,
140L, 210L, 60L, 50L, 90L, 120L, 55L, 50L, 20L, 50L, 40L,
70L, 40L, 100L, 80L, 85L, 60L, 50L, 20L, 200L, 40L, 70L,
50L, 200L, 60L, 43L, 30L, 60L, 40L, 70L, 40L, 40L, 40L, 50L,
110L, 70L, 30L, 50L, 85L, 70L, 40L, 100L, 40L, 50L, 100L,
40L, 70L, 40L, 40L, 50L, 210L, 50L, 140L, 80L, 75L, 90L,
40L, 50L, 60L, 50L, 80L, 50L, 60L, 40L, 60L, 170L, 60L, 80L,
80L, 15L, 40L, 70L, 45L, 45L, 45L, 110L, 200L, 30L, 60L,
40L, 60L, 160L, 40L, 90L, 80L, 30L, 40L, 270L, 50L, 50L,
60L, 60L, 50L, 30L, 70L, 170L, 50L, 30L, 50L, 60L, 40L, 60L,
60L, 140L, 80L, 80L, 220L, 45L, 80L, 130L, 50L, 40L, 220L,
40L, 70L, 60L, 80L, 50L, 200L, 115L, 50L, 90L, 400L, 50L,
360L, 40L, 60L, 60L, 65L, 100L, 50L, 55L, 60L, 50L, 130L,
40L, 130L, 40L, 40L, 120L, 66L, 55L, 100L, 75L, 60L, 80L,
60L, 90L, 160L, 50L, 210L, 35L, 60L, 40L, 55L, 50L, 90L,
220L, 60L, 120L, 62L, 60L, 40L, 60L, 70L, 60L, 90L, 50L,
50L, 30L, 110L, 70L, 80L, 90L, 210L, 70L, 65L, 160L, 100L,
25L, 55L, 40L, 60L, 110L, 70L, 50L, 60L, 70L, 60L, 60L, 170L,
45L, 60L, 120L, 40L, 60L, 130L, 40L, 170L, 50L, 80L, 60L,
150L, 90L, 60L, 120L, 120L, 80L, 30L, 110L, 230L, 190L, 70L,
110L, 50L, 60L, 82L, 60L, 30L, 60L, 200L, 90L, 30L, 140L,
60L, 70L, 70L, 100L, 60L, 415L, 115L, 90L, 60L, 60L, 80L,
60L, 55L, 90L, 65L, 60L, 40L, 40L, 90L, 50L, 70L, 70L, 120L,
40L, 50L, 110L, 45L, 30L, 95L, 30L, 70L), width = c(310L,
50L, 40L, 30L, 60L, 70L, 20L, 80L, 70L, 20L, 220L, 40L, 60L,
30L, 230L, 110L, 20L, 40L, 25L, 60L, 240L, 90L, 30L, 130L,
120L, 110L, 60L, 70L, 30L, 110L, 30L, 180L, 20L, 80L, 110L,
310L, 40L, 10L, 80L, 160L, 134L, 30L, 20L, 40L, 20L, 230L,
100L, 180L, 40L, 120L, 130L, 30L, 40L, 100L, 30L, 180L, 70L,
110L, 170L, 40L, 30L, 50L, 30L, 40L, 30L, 50L, 80L, 50L,
80L, 90L, 70L, 70L, 190L, 60L, 50L, 30L, 150L, 150L, 50L,
80L, 30L, 40L, 130L, 390L, 60L, 130L, 400L, 200L, 110L, 30L,
15L, 300L, 70L, 140L, 30L, 50L, 30L, 40L, 110L, 240L, 50L,
90L, 70L, 20L, 40L, 100L, 50L, 30L, 30L, 130L, 40L, 70L,
70L, 60L, 10L, 30L, 60L, 50L, 40L, 120L, 90L, 210L, 50L,
20L, 100L, 100L, 110L, 100L, 100L, 80L, 120L, 80L, 5L, 40L,
50L, 60L, 15L, 100L, 120L, 200L, 30L, 80L, 60L, 70L, 30L,
30L, 20L, 50L, 50L, 60L, 15L, 80L, 60L, 130L, 40L, 60L, 30L,
100L, 20L, 130L, 60L, 120L, 70L, 20L, 60L, 20L, 40L, 50L,
15L, 120L, 60L, 50L, 300L, 40L, 30L, 25L, 70L, 130L, 30L,
50L, 60L, 50L, 50L, 50L, 20L, 30L, 70L, 35L, 180L, 40L, 50L,
70L, 40L, 70L, 50L, 20L, 40L, 40L, 40L, 40L, 50L, 20L, 30L,
180L, 30L, 130L, 30L, 15L, 25L, 50L, 40L, 40L, 40L, 50L,
170L, 20L, 50L, 20L, 50L, 110L, 30L, 90L, 15L, 50L, 40L,
150L, 30L, 30L, 30L, 20L, 40L, 20L, 100L, 60L, 40L, 30L,
30L, 140L, 40L, 50L, 120L, 150L, 100L, 70L, 300L, 30L, 60L,
120L, 30L, 50L, 100L, 60L, 90L, 50L, 40L, 140L, 130L, 60L,
60L, 70L, 200L, 30L, 40L, 50L, 20L, 20L, 20L, 80L, 35L, 70L,
15L, 40L, 360L, 70L, 50L, 50L, 30L, 110L, 30L, 30L, 90L,
50L, 30L, 70L, 40L, 110L, 70L, 40L, 150L, 100L, 40L, 40L,
40L, 20L, 250L, 180L, 40L, 60L, 20L, 120L, 40L, 50L, 60L,
260L, 110L, 30L, 30L, 40L, 100L, 50L, 50L, 100L, 150L, 190L,
70L, 110L, 50L, 10L, 40L, 50L, 60L, 80L, 30L, 20L, 150L,
70L, 25L, 30L, 40L, 50L, 30L, 50L, 210L, 40L, 100L, 30L,
80L, 20L, 30L, 70L, 130L, 60L, 50L, 50L, 70L, 50L, 30L, 150L,
130L, 110L, 50L, 40L, 80L, 90L, 40L, 40L, 40L, 40L, 200L,
140L, 40L, 25L, 50L, 50L, 40L, 20L, 40L, 340L, 70L, 60L,
50L, 20L, 80L, 60L, 25L, 260L, 20L, 15L, 40L, 30L, 300L,
120L, 60L, 100L, 50L, 40L, 20L, 90L, 50L, 40L, 80L, 30L,
40L), length = c(450L, 80L, 55L, 50L, 90L, 90L, 30L, 90L,
90L, 30L, 240L, 50L, 70L, 40L, 380L, 200L, 40L, 40L, 35L,
110L, 250L, 120L, 70L, 150L, 130L, 140L, 90L, 90L, 40L, 390L,
40L, 190L, 40L, 110L, 140L, 360L, 50L, 30L, 130L, 500L, 200L,
30L, 25L, 60L, 30L, 350L, 110L, 180L, 70L, 180L, 200L, 40L,
70L, 110L, 70L, 180L, 90L, 150L, 400L, 100L, 60L, 70L, 70L,
60L, 30L, 50L, 80L, 180L, 110L, 100L, 110L, 110L, 210L, 80L,
70L, 40L, 500L, 210L, 50L, 80L, 40L, 50L, 350L, 400L, 150L,
200L, 400L, 280L, 240L, 40L, 50L, 360L, 140L, 140L, 50L,
50L, 40L, 50L, 210L, 370L, 70L, 110L, 80L, 50L, 50L, 100L,
80L, 50L, 35L, 140L, 60L, 90L, 110L, 60L, 130L, 180L, 70L,
70L, 40L, 230L, 130L, 290L, 90L, 40L, 100L, 100L, 120L, 150L,
110L, 80L, 220L, 90L, 5L, 50L, 50L, 60L, 30L, 150L, 120L,
200L, 60L, 170L, 80L, 90L, 40L, 50L, 70L, 50L, 60L, 100L,
15L, 90L, 70L, 150L, 60L, 90L, 50L, 120L, 20L, 220L, 80L,
140L, 120L, 30L, 60L, 40L, 40L, 70L, 30L, 180L, 60L, 110L,
300L, 50L, 60L, 50L, 110L, 160L, 40L, 70L, 70L, 60L, 70L,
50L, 25L, 30L, 215L, 70L, 220L, 70L, 80L, 90L, 60L, 130L,
60L, 20L, 60L, 50L, 40L, 60L, 100L, 40L, 70L, 210L, 40L,
500L, 40L, 30L, 50L, 80L, 40L, 60L, 80L, 50L, 220L, 20L,
70L, 50L, 50L, 180L, 50L, 90L, 15L, 120L, 80L, 170L, 30L,
30L, 60L, 20L, 60L, 30L, 140L, 80L, 40L, 50L, 40L, 200L,
80L, 80L, 120L, 160L, 210L, 120L, 400L, 60L, 60L, 180L, 70L,
70L, 150L, 70L, 110L, 70L, 80L, 250L, 140L, 90L, 60L, 180L,
400L, 60L, 50L, 60L, 40L, 30L, 50L, 100L, 40L, 110L, 30L,
80L, 400L, 70L, 50L, 80L, 30L, 180L, 70L, 60L, 100L, 70L,
50L, 100L, 60L, 220L, 70L, 70L, 200L, 110L, 50L, 110L, 50L,
60L, 250L, 220L, 60L, 80L, 35L, 210L, 70L, 70L, 110L, 320L,
280L, 60L, 50L, 60L, 100L, 70L, 70L, 170L, 170L, 230L, 80L,
130L, 90L, 10L, 60L, 70L, 60L, 120L, 40L, 50L, 160L, 100L,
30L, 40L, 40L, 90L, 30L, 80L, 240L, 100L, 170L, 60L, 120L,
20L, 40L, 70L, 150L, 80L, 50L, 90L, 130L, 70L, 60L, 480L,
150L, 130L, 90L, 70L, 150L, 100L, 70L, 50L, 40L, 60L, 400L,
200L, 80L, 30L, 120L, 70L, 50L, 40L, 40L, 360L, 90L, 70L,
60L, 40L, 110L, 80L, 25L, 270L, 40L, 25L, 50L, 30L, 320L,
150L, 100L, 100L, 60L, 40L, 50L, 100L, 50L, 50L, 200L, 30L,
80L), ground = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 3L, 1L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 3L,
1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L,
1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 3L, 2L,
2L, 1L,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 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L,
1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L,
0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L,
1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L,
1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L,
0L)), .Names = c("site", "species", "aspect", "height", "width",
"length", "ground", "sun", "leaf", "Presence"), row.names = c(NA,
393L), class = "data.frame")
After the model selection, this is the optimal model:
model <- glm(Presence ~ site + species + aspect + length + sun
+ leaf, data=MyData, family=binomial)
With respect to the 1st way referred to above, one can do the following:
library(car)
vif(model)
to obtain VIFs based on the model as an input.
But with respect to 2nd way, one could look at VIFs of variables, before fitting the model:
library(AED) # note that his package has been discontinued
vars <- cbind(MyData$site, MyData$species,
MyData$aspect , MyData$length ,
MyData$width, MyData$height,
MyData$ground, MyData$sun, MyData$leaf)
corvif(vars)
(the corvif() function code can be found here: http://www.highstat.com/Book2/HighstatLibV6.R)
The underlying mathematics of the two functions appear to be the same, but the way the functions are written, they accept different types of objects as input.
My questions are:
Do you prefer to calculate VIFs based
on a list of variables prior to model fitting,
on a fitted model, or
both?
Are there any functions (in additions to the two referred to already) that people recommend and/or use to calculate VIFs?
Is anyone aware of a single R function that works on both the list of variables and the fitted model as in input?
My (opinionated) answer to the question: whether it's more appropriate to use vif on a model object or on the data itself, would be that it would be best practice to do it before the model is constructed as part of the process of understanding the relationships within the data before modeling. But truth be told, I think most of the time it's done as an afterthought because of unexpected results (standard errors that blow up, usually).
If you want a function that can take either a fit object or a dimensioned data-object (matrix or dataframe), then I think you may need to "roll your own". I have used the rms/Hmisc pair of packages extensively and there is also a vif in the 'rms'-package as well as a which.influence function that lets you know the combinations that are responsible for the multicollinearity. It only accepts a fit-object. Because the versions that handle fit-objects can look at both the result of vcov and the terms in the RHS of the formula, you would only need to have single argument. However, if you want to specify which columns to examine in a dimensioned object, then you would need to provide function code to handle a second parameter.
I did a search with:
sos::findFn("vif")
... and the fourth page examined (function vif in package "HH") appears to offer a choice of which strategy to use: http://finzi.psych.upenn.edu/R/library/HH/html/vif.html
If you wanted to write your own, then you already have the code in the form of the corvif and myvif functions on the page you linked to. The corvif function uses the myvif function, which is model-based. So you could insert code to check for the presence of the first argument's class in the vector of methods returned by methods(vcov).
In the question presented here, sample data was converted from wide to long format using dcast. However, when attempting to apply the same approach to the actual data set (or an abbreviated form thereof):
dcast(melt(smallz, 1:2), behavior_num + variable ~ rater)
The factors for the variable (i.e., the original column 3), are displayed as integers.
(Why) are the factors being displayed as integers?
How might they still be displayed as characters?
The smaller data subset is here:
structure(list(rater = structure(c(2L, 1L, 6L, 7L, 3L, 5L, 4L,
2L, 1L, 6L, 7L, 3L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, 6L, 7L, 3L, 5L, 4L, 2L, 1L, 6L, 7L, 3L, 5L,
4L, 2L, 1L, 6L, 7L, 3L, 5L, 4L, 2L, 1L, 6L, 7L, 3L, 5L, 4L), .Label = c("Al",
"Dan", "Gabi", "john", "bill", "rebecca",
"ted"), class = "factor"), behavior_num = c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 41L, 41L, 41L, 41L, 41L, 41L,
41L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 49L, 49L, 49L, 49L, 49L,
49L, 49L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 58L, 58L, 58L, 58L,
58L, 58L, 58L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 66L, 66L, 66L,
66L, 66L, 66L, 66L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 73L, 73L,
73L, 73L, 73L, 73L, 73L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 84L,
84L, 84L, 84L, 84L, 84L, 84L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 116L, 116L, 116L, 116L, 116L, 116L, 116L, 121L, 121L, 121L,
121L, 121L, 121L, 121L, 122L, 122L, 122L, 122L, 122L, 122L, 122L,
127L, 127L, 127L, 127L, 127L, 127L, 127L, 132L, 132L, 132L, 132L,
132L, 132L, 132L, 133L, 133L, 133L, 133L, 133L, 133L, 133L, 135L,
135L, 135L, 135L, 135L, 135L, 135L, 142L, 142L, 142L, 142L, 142L,
142L, 142L, 145L, 145L, 145L, 145L, 145L, 145L, 145L, 147L, 147L,
147L, 147L, 147L, 147L, 147L, 155L, 155L, 155L, 155L, 155L, 155L,
155L, 162L, 162L, 162L, 162L, 162L, 162L, 162L, 173L, 173L, 173L,
173L, 173L, 173L, 173L, 178L, 178L, 178L, 178L, 178L, 178L, 178L,
179L, 179L, 179L, 179L, 179L, 179L, 179L, 182L, 182L, 182L, 182L,
182L, 182L, 182L, 183L, 183L, 183L, 183L, 183L, 183L, 183L, 186L,
186L, 186L, 186L, 186L, 186L, 186L, 193L, 193L, 193L, 193L, 193L,
193L, 193L, 196L, 196L, 196L, 196L, 196L, 196L, 196L, 204L, 204L,
204L, 204L, 204L, 204L, 204L, 206L, 206L, 206L, 206L, 206L, 206L,
206L, 207L, 207L, 207L, 207L, 207L, 207L, 207L, 211L, 211L, 211L,
211L, 211L, 211L, 211L, 211L, 231L, 231L, 231L, 231L, 231L, 231L
), self.and.tech = structure(c(2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 3L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L,
2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L,
2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 1L, 3L, 3L, 2L, 3L, 2L,
3L, 1L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 1L, 3L,
3L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 1L, 1L,
1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 2L, 1L, 2L, 2L, 1L,
3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L), .Label = c("more commonly reinforced",
"neither a history of reinforcement or punishment are discernible from the behaviors evidenced",
"more commonly punished"), class = "factor")), .Names = c("rater",
"behavior_num", "self.and.tech"), row.names = c(NA, -294L), class = "data.frame"
I have a dataframe df
df<-structure(list(subject = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,
36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L,
49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L), sex = c(1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L,
2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L,
2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L), age = c(29L, 54L, 67L,
36L, 48L, 37L, 25L, 46L, 37L, 33L, 25L, 26L, 28L, 59L, 46L, 50L,
55L, 56L, 37L, 30L, 38L, 30L, 50L, 39L, 29L, 46L, 48L, 46L, 55L,
32L, 66L, 35L, 48L, 54L, 38L, 31L, 42L, 36L, 27L, 63L, 45L, 31L,
26L, 38L, 43L, 52L, 36L, 43L, 65L, 46L, 42L, 29L, 54L, 67L, 36L,
48L, 37L, 25L, 46L, 37L, 33L, 25L, 26L, 28L, 59L, 46L, 50L, 55L,
56L, 37L, 30L, 38L, 30L, 50L, 39L, 29L, 46L, 48L, 46L, 55L, 32L,
66L, 35L, 48L, 54L, 38L, 31L, 42L, 36L, 27L, 63L, 45L, 31L, 26L,
38L, 43L, 52L, 36L, 43L, 65L, 46L, 42L), edu = c(4L, 3L, 3L,
3L, 4L, 2L, 3L, 3L, 1L, 3L, 4L, 4L, 5L, 1L, 1L, 2L, 2L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 2L, 2L, 1L, 2L, 2L, 4L, 2L, 4L, 4L, 3L, 3L,
4L, 5L, 3L, 3L, 4L, 1L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 6L, 1L, 3L,
4L, 3L, 3L, 3L, 4L, 2L, 3L, 3L, 1L, 3L, 4L, 4L, 5L, 1L, 1L, 2L,
2L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 1L, 2L, 2L, 4L, 2L, 4L,
4L, 3L, 3L, 4L, 5L, 3L, 3L, 4L, 1L, 1L, 3L, 1L, 3L, 1L, 3L, 1L,
6L, 1L, 3L), biz_exp = c(5L, 15L, 3L, 4L, 10L, 6L, 0L, 5L, 8L,
5L, 0L, 8L, 3L, 23L, 5L, 7L, 5L, 11L, 4L, 4L, 11L, 3L, 15L, 4L,
4L, 6L, 6L, 5L, 13L, 2L, 13L, 6L, 8L, 27L, 7L, 3L, 11L, 5L, 1L,
4L, 8L, 8L, 4L, 15L, 18L, 30L, 9L, 14L, 18L, 21L, 16L, 5L, 15L,
3L, 4L, 10L, 6L, 0L, 5L, 8L, 5L, 0L, 8L, 3L, 23L, 5L, 7L, 5L,
11L, 4L, 4L, 11L, 3L, 15L, 4L, 4L, 6L, 6L, 5L, 13L, 2L, 13L,
6L, 8L, 27L, 7L, 3L, 11L, 5L, 1L, 4L, 8L, 8L, 4L, 15L, 18L, 30L,
9L, 14L, 18L, 21L, 16L), turnov = c(36L, NA, 12L, 9L, 48L, 9L,
8L, 24L, 4L, 250L, NA, 600L, 6L, 6L, 10L, 10L, 5L, 4L, 250L,
200L, 50L, 150L, 48L, NA, 9L, 6L, 2L, NA, NA, 3L, 7L, 23L, 75L,
7L, 5L, NA, 20L, 450L, 5L, 32L, 21L, 12L, 6L, 4L, 24L, 7L, 10L,
12L, 12L, 14L, 18L, 36L, NA, 12L, 9L, 48L, 9L, 8L, 24L, 4L, 250L,
NA, 600L, 6L, 6L, 10L, 10L, 5L, 4L, 250L, 200L, 50L, 150L, 48L,
NA, 9L, 6L, 2L, NA, NA, 3L, 7L, 23L, 75L, 7L, 5L, NA, 20L, 450L,
5L, 32L, 21L, 12L, 6L, 4L, 24L, 7L, 10L, 12L, 12L, 14L, 18L),
loc_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, 3L, 3L, 4L, 3L), .Label = c("1", "2",
"3", "4", "MA"), class = "factor"), bundle = c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), investment = c(86L,
100L, 100L, 75L, 100L, 59L, 68L, 86L, 80L, 100L, 86L, 100L,
100L, 100L, 100L, 100L, 100L, 93L, 64L, 100L, 24L, 18L, 89L,
75L, 80L, 29L, 54L, 65L, 100L, 27L, 59L, 30L, 59L, 43L, 59L,
59L, 5L, 26L, 100L, 75L, 59L, 5L, 59L, 74L, 59L, 79L, 75L,
75L, 86L, 66L, 86L, 55L, 100L, 68L, 1L, 75L, 1L, 1L, 79L,
1L, 54L, 48L, 33L, 55L, 90L, 85L, 39L, 70L, 1L, 45L, 54L,
33L, 3L, 44L, 75L, 1L, 1L, 1L, 1L, 96L, 26L, 1L, 23L, 66L,
1L, 89L, 83L, 52L, 61L, 1L, 88L, 45L, 72L, 60L, 1L, 60L,
2L, 86L, 10L, 63L, 1L, 88L)), .Names = c("subject", "sex",
"age", "edu", "biz_exp", "turnov", "loc_pr", "type", "age_rec",
"biz_exp_rec", "turnov_rec", "bundle", "investment"), class = "data.frame", row.names = c(NA,
-102L))
In this dataframe investment is my dependent variable and the other variables are my independent variables. My subjects are crossed within type of bundle. First of all, I would like know whether my subjects do bundle or not (bundle= 1 means that people bundle and bundle=0 means that people do not bundle), it will have an effect on the investment.
I have done this mixed effect linear model but I am not sure if this is correct as my p-value are equal to zero.
library(nlme)
model <- lme(investment~bundle, random = ~1|subject/bundle, data=df)
I have also tried to make an anova with repeated measures as such:
aov(investment~bundle+ Error(subject/bundle), data=df)
It works but not sure if the model formula is right
Anyone could help me with that?