Factors being converted / displayed as integers in R after dcast - r

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, 5L, 4L, 2L, 1L, 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, 2L, 1L, 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, 2L,
1L, 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, 2L, 1L, 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, 2L, 1L, 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, 2L, 1L, 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, 2L,
1L, 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, 2L, 1L, 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, 2L, 1L, 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, 2L, 1L, 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"

Related

Error using 'poly': 'degree' must be less than number of unique points while using 'effects' package

I am trying to use the effects package to create plots of effects in a linear mixed model. I specify the model
fit1 <- lmer(Values ~ stimuli + timeperiod + scale(poly(distance.code,3,raw=FALSE))*habitat + wind.speed + (1|location.code), data=ex.df, REML=FALSE)
For this model I can generate results for analysis as I expect using summary or anova but when I try to look at specific effects:
allEffects(fit1)
#or
plot(allEffects(fit1))
#or
emmeans(fit1, pairwise ~ stimuli)
An error is returned:
Error in poly(distance.code, 3, raw = FALSE) :
'degree' must be less than number of unique points
(with the plot function the error is different but is probably arising from the error with allEffects)
I understand, based on the responses to this question and this question, that "numerical overflow" can be an issue with poly terms. However, I am not clear on what this means or how to overcome the issue.
I also saw in this post and in another post about lme4 that I can no longer find, that I might need to update packages so I have updated 'effects' and 'lme4' in an attempt to remedy this but to no avail.
So if this error is happening because of "numerical overflow" how can I remedy the problem? or if it is not numerical overflow what is happening and how can I work around this?
a subset of my data using dput is:
structure(list(location.code = structure(c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 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 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("before",
"during", "after"), class = "factor"), timeperiod = c(6L, 6L,
6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L), distance.code = c(0L, 30L, 60L,
120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L,
30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L,
120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L,
0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L,
120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L,
120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L,
120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L,
60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L),
Values = c(910.721895276374, 922.652711611841, 926.219785713456,
918.776924477918, 1030.28919690464, 1121.98321368732, 992.741416151102,
910.878353926705, 920.201901019659, 922.134996121665, 917.610324052986,
992.059286431433, 1042.05240231832, 1018.99804250179, 911.976009884021,
918.215389274037, 931.037495260958, 913.49701806948, 981.032280455129,
983.700699744073, 989.716307418049, 911.476759038955, 918.554393750162,
920.391856289719, 911.795802370903, 994.583211567691, 1006.58290843226,
1005.52479816571, 908.665064025178, 917.940176257067, 922.746174825048,
921.752449434568, 986.419049170517, 1042.41789735969, 1082.89658057517,
916.02310296116, 918.254868924698, 931.01648294424, 924.221021573334,
982.154409713674, 1008.54477137219, 996.577798511801, 912.914857937818,
916.937508116615, 920.933077377339, 917.443294381608, 997.669828575817,
1007.44452218386, 1151.25894192961, 909.463528658898, 915.293665875472,
921.917039784441, 912.073280663674, 983.866984633392, 1002.04551764872,
986.791628665069, 907.695668282537, 917.845214744473, 932.330755620455,
917.500330773026, 972.609449456089, 1155.55960936774, 1083.40557091613,
909.903267624225, 914.846316952797, 921.279328283221, 914.498616645498,
1000.3672969178, 1021.78461788922, 1011.40975353271, 915.037273600535,
914.099859036178, 924.116937361394, 913.523739017819, 994.428182266452,
1123.09745015276, 1004.1485272116, 914.431649376896, 915.27037594587,
929.411251949862, 910.549315840806, 974.273124973661, 1145.99211507205,
1013.58184367388, 913.467056616881, 920.213007520924, 919.794369158301,
912.333012054637, 983.816025282468, 1103.11322201674, 974.792027063404,
910.532609655114, 917.616832229923, 923.462599912213, 913.432298686233,
1015.24811721269, 1070.61183211249, 1016.57332551186, 910.196695694198,
923.403802532832, 905.400995326023, 934.612035397761, 1036.98011238981,
963.147077473505, 953.792949959199, 916.899569521736, 931.240844862156,
919.11781354823, 938.028220926723, 995.408916523572, 960.825305234446,
993.019295484939, 1026.22960551445, 1000.13773127026, 962.347584090332,
1074.31979099791, 904.090295814044, 908.836747102913, 928.867625382891,
918.100799763641, 906.282906701285, 913.146312873635, 921.224088728859,
977.094140033575, 972.599778534534, 964.658406857446, 1197.35130424458,
921.91272768213, 910.507770576621, 942.269786765654, 922.718235872787,
1014.34022271036, 1128.29327664605, 1043.1365958913, 1238.18704569961,
919.185972424773, 925.486310755197, 908.769520270226, 919.644447501213,
1030.20866627018, 956.104935565803, 955.159231718685, 922.01947330213,
934.451182538208, 928.626906337293, 941.089746683706, 986.326936258622,
1003.40797963907, 1007.57786522109, 1021.91264348048, 995.68658929192,
993.102343807935, 1114.80420865448, 901.633626404701, 908.255562868123,
922.840049924103, 917.012733437446, 907.541530752433, 915.050696506642,
925.95358291661, 983.542956895186, 972.236377246083, 965.082329354352,
1205.36753472358, 918.337944633569, 910.137012141557, 952.89462134025,
923.334999242316, 977.420371016686, 1154.17994731565, 1022.82998099991,
1186.66254220951, 927.061613377597, 926.745527716988, 908.284054932259,
921.213190559531, 966.157586219165, 974.986841619676, 959.421220417498,
916.559494755925, 935.817296050643, 918.835719171662, 912.457217113586,
1023.62078549133, 1009.23121097376, 978.938675917385, 1005.81651905991,
981.715747809821, 953.127134375762, 1088.16577366048, 902.809201411559,
907.462229880533, 921.595454423298, 919.198277947855, 904.969515265664,
913.438353334218, 918.91715550342, 974.889830301362, 970.58615968713,
963.029605541189, 1182.94093491074, 915.889893279581, 908.147726780027,
942.742415528349, 928.20319656241, 979.939535179807, 1153.51966568673,
1020.93502990084, 1154.799618481, 916.246150801212, 936.016759720656,
914.4488779132, 918.823772018551, 962.397352323664, 986.957848140285,
972.131488585193, 985.364195731404, 932.548910038465, 917.363220594089,
919.124801182577, 1085.89850605988, 1031.66330597084, 974.763804119707,
1005.64983154588, 991.988118229379, 975.384741587994, 1064.14809010237,
902.60240793926, 907.989086075871, 923.287310593779, 912.878571722023,
904.107623756648, 905.563259817979, 917.423553921906, 991.530368160932,
975.190212414434, 965.951810135591, 1192.3330908297, 915.334621878897,
910.857441830446, 936.093336975328, 932.960789822422, 972.074491630181,
1106.77459226532, 993.45400883741, 1138.94109332484, 951.911391767329,
927.688604859773, 915.194279622847, 920.98264624041, 971.414103170297,
956.138106650696, 969.385400747507, 965.458656222347, 944.097918792458,
947.157460200658, 915.929397317864, 1029.14870726558, 992.151638322899,
964.680220137879, 954.129642526236, 981.48182339388, 968.10870393618,
1097.48462256339, 906.941701681267, 917.956716926981, 923.05649603805,
934.459432014683, 922.801034508827, 920.724850575215, 935.811146196027,
981.478432929603, 1012.67364507927, 966.471299899978, 1192.4066704659,
912.640460101352, 906.34455384334, 923.738349342148, 916.883929696437,
970.987788560016, 1210.42940542072, 975.753397539076, 1138.97675920151,
911.747488522664, 928.34872697947, 910.852487444859, 916.227875349016,
982.304620375747, 1028.52794775628, 999.236663664046, 913.408967803895,
934.334726415048, 916.354017093653, 918.660674732388, 1036.08727658415,
974.408618327141, 1006.21629092128, 1004.71633485176, 995.142763465394,
987.00017276687), wind.speed = c(0.8, 0.8, 0.8, 0.8, 0.2,
0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8,
0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8,
0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2,
0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8,
0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8,
0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2,
0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2,
0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 65, 65, 65,
65, 65, 65, 65, 55, 55, 55, 55, 50, 50, 50, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9,
0.9, 65, 65, 65, 65, 65, 65, 65, 55, 55, 55, 55, 50, 50,
50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0.9, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 65, 65, 55, 55,
55, 55, 50, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65,
65, 65, 55, 55, 55, 55, 50, 50, 50, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 0.9, 65,
65, 65, 65, 65, 65, 65, 55, 55, 55, 55, 50, 50, 50, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9,
0.9, 0.9, 65, 65, 65, 65, 65, 65, 65, 55, 55, 55, 55, 50,
50, 50, 0, 0, 0)), row.names = c(85L, 86L, 87L, 88L, 89L,
90L, 91L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 113L, 114L,
115L, 116L, 117L, 118L, 119L, 127L, 128L, 129L, 130L, 131L, 132L,
133L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 155L, 156L, 157L,
158L, 159L, 160L, 161L, 169L, 170L, 171L, 172L, 173L, 174L, 175L,
183L, 184L, 185L, 186L, 187L, 188L, 189L, 197L, 198L, 199L, 200L,
201L, 202L, 203L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 225L,
226L, 227L, 228L, 229L, 230L, 231L, 239L, 240L, 241L, 242L, 243L,
244L, 245L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 267L, 268L,
269L, 270L, 271L, 272L, 273L, 615L, 616L, 617L, 618L, 619L, 620L,
621L, 622L, 623L, 624L, 625L, 626L, 627L, 628L, 629L, 630L, 631L,
632L, 640L, 641L, 642L, 643L, 644L, 645L, 646L, 647L, 648L, 649L,
650L, 651L, 652L, 653L, 654L, 655L, 656L, 657L, 658L, 659L, 660L,
661L, 662L, 663L, 664L, 665L, 666L, 667L, 668L, 669L, 670L, 671L,
672L, 673L, 674L, 675L, 676L, 684L, 685L, 686L, 687L, 688L, 689L,
690L, 691L, 692L, 693L, 694L, 695L, 696L, 697L, 698L, 699L, 700L,
701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L, 710L, 711L,
712L, 713L, 714L, 715L, 716L, 717L, 718L, 719L, 720L, 728L, 729L,
730L, 731L, 732L, 733L, 734L, 735L, 736L, 737L, 738L, 739L, 740L,
741L, 742L, 743L, 744L, 745L, 746L, 747L, 748L, 749L, 750L, 751L,
752L, 753L, 754L, 755L, 756L, 757L, 758L, 759L, 760L, 761L, 762L,
763L, 764L, 772L, 773L, 774L, 775L, 776L, 777L, 778L, 779L, 780L,
781L, 782L, 783L, 784L, 785L, 786L, 787L, 788L, 789L, 790L, 791L,
792L, 793L, 794L, 795L, 796L, 797L, 798L, 799L, 800L, 801L, 802L,
803L, 804L, 805L, 806L, 807L, 808L, 816L, 817L, 818L, 819L, 820L,
821L, 822L, 823L, 824L, 825L, 826L, 827L, 828L, 829L, 830L, 831L,
832L, 833L, 834L, 835L, 836L, 837L, 838L, 839L, 840L, 841L, 842L,
843L, 844L, 845L, 846L, 847L, 848L, 849L, 850L, 851L), class = "data.frame")
> ex.df <- head(ex.df, 100)
> dput(ex.df)
structure(list(location.code = structure(c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L), .Label = c("BSF1",
"BSG1", "RLF3", "RLG3", "CCBSF1", "CCBSG1", "CPF1", "CPF2", "CPG1",
"CPG2", "OSG1", "OSG2", "RLF4", "RLF5", "RLF1", "RLF2", "RLG1",
"RLG2", "BNPF1", "BNPG1", "OSG3", "OSF1", "CMG3", "CMF1", "BSG2",
"BSG3", "WSF1", "WSF2", "HPG1", "HPG2"), class = "factor"), stim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 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
1L, 1L), .Label = c("before", "during", "after"), class = "factor"),
timeperiod = c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
6L, 6L), distance.code = c(0L, 30L, 60L, 120L, 0L, 30L, 60L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L,
30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L,
120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L), Values = c(910.721895276374,
922.652711611841, 926.219785713456, 918.776924477918, 1030.28919690464,
1121.98321368732, 992.741416151102, 910.878353926705, 920.201901019659,
922.134996121665, 917.610324052986, 992.059286431433, 1042.05240231832,
1018.99804250179, 911.976009884021, 918.215389274037, 931.037495260958,
913.49701806948, 981.032280455129, 983.700699744073, 989.716307418049,
911.476759038955, 918.554393750162, 920.391856289719, 911.795802370903,
994.583211567691, 1006.58290843226, 1005.52479816571, 908.665064025178,
917.940176257067, 922.746174825048, 921.752449434568, 986.419049170517,
1042.41789735969, 1082.89658057517, 916.02310296116, 918.254868924698,
931.01648294424, 924.221021573334, 982.154409713674, 1008.54477137219,
996.577798511801, 912.914857937818, 916.937508116615, 920.933077377339,
917.443294381608, 997.669828575817, 1007.44452218386, 1151.25894192961,
909.463528658898, 915.293665875472, 921.917039784441, 912.073280663674,
983.866984633392, 1002.04551764872, 986.791628665069, 907.695668282537,
917.845214744473, 932.330755620455, 917.500330773026, 972.609449456089,
1155.55960936774, 1083.40557091613, 909.903267624225, 914.846316952797,
921.279328283221, 914.498616645498, 1000.3672969178, 1021.78461788922,
1011.40975353271, 915.037273600535, 914.099859036178, 924.116937361394,
913.523739017819, 994.428182266452, 1123.09745015276, 1004.1485272116,
914.431649376896, 915.27037594587, 929.411251949862, 910.549315840806,
974.273124973661, 1145.99211507205, 1013.58184367388, 913.467056616881,
920.213007520924, 919.794369158301, 912.333012054637, 983.816025282468,
1103.11322201674, 974.792027063404, 910.532609655114, 917.616832229923,
923.462599912213, 913.432298686233, 1015.24811721269, 1070.61183211249,
1016.57332551186, 910.196695694198, 923.403802532832), wind.speed = c(0.8,
0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2,
0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8,
0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8,
0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2,
0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2,
0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8,
0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8,
0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2,
0.2, 65, 65)), row.names = c(85L, 86L, 87L, 88L, 89L, 90L,
91L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 113L, 114L, 115L,
116L, 117L, 118L, 119L, 127L, 128L, 129L, 130L, 131L, 132L, 133L,
141L, 142L, 143L, 144L, 145L, 146L, 147L, 155L, 156L, 157L, 158L,
159L, 160L, 161L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 183L,
184L, 185L, 186L, 187L, 188L, 189L, 197L, 198L, 199L, 200L, 201L,
202L, 203L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 225L, 226L,
227L, 228L, 229L, 230L, 231L, 239L, 240L, 241L, 242L, 243L, 244L,
245L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 267L, 268L, 269L,
270L, 271L, 272L, 273L, 615L, 616L), class = "data.frame")
Thanks for any help!
EDIT!!
I ran terms(fit1) as suggested in the comments, the results were as follows:
terms(fit1)
Values ~ stimuli + timeperiod + scale(poly(distance.code, 3,
raw = FALSE)) * habitat + wind.speed
attr(,"variables")
list(Values, stimuli, timeperiod, scale(poly(distance.code, 3,
raw = FALSE)), habitat, wind.speed)
attr(,"factors")
stimuli timeperiod scale(poly(distance.code, 3, raw = FALSE)) habitat wind.speed
Values 0 0 0 0 0
stimuli 1 0 0 0 0
timeperiod 0 1 0 0 0
scale(poly(distance.code, 3, raw = FALSE)) 0 0 1 0 0
habitat 0 0 0 1 0
wind.speed 0 0 0 0 1
scale(poly(distance.code, 3, raw = FALSE)):habitat
Values 0
stimuli 0
timeperiod 0
scale(poly(distance.code, 3, raw = FALSE)) 1
habitat 1
wind.speed 0
attr(,"term.labels")
[1] "stimuli" "timeperiod"
[3] "scale(poly(distance.code, 3, raw = FALSE))" "habitat"
[5] "wind.speed" "scale(poly(distance.code, 3, raw = FALSE)):habitat"
attr(,"order")
[1] 1 1 1 1 1 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(Values, stimuli, timeperiod, scale(poly(distance.code, 3,
raw = FALSE)), habitat, wind.speed)
Here is a simple parallel example illustrating that wrapping poly() in scale() is the culprit:
> library(emmeans)
> mod1 = lm(mpg ~ am + poly(disp, 3), data = mtcars)
> ref_grid(mod1)
'emmGrid' object with variables:
am = 0, 1
disp = 230.72
> mod2 = lm(mpg ~ am + scale(poly(disp, 3)), data = mtcars)
> ref_grid(mod2)
Error in poly(disp, 3) :
'degree' must be less than number of unique points
Specifically, the call to scale() messes up the predvars attribute in the model's terms component:
> attr(terms(mod1), "predvars")
list(mpg, am, poly(disp, 3, coefs = list(alpha = c(230.721875,
279.549822668452, 298.198735227759), norm2 = c(1, 32, 476184.7946875,
5315202742.2241, 64139299346388.8))))
This provides the coefficients needed to construct the orthogonal polynomial basis; whereas...
> attr(terms(mod2), "predvars")
list(mpg, am, scale(poly(disp, 3)))
That information is excluded.
Note that the scale() call is completely unnecessary anyway, as poly() generates an orthonormal matrix of predictors.

Is it possible to table() two columns in a way that display the sum horizontally and vertically?

I have
> table(y$treatment,y$WHO)
1 2 3 4
SSTR 43 34 20 27
SSA 23 28 25 0
Control 0 0 0 0
I am looking for a way to display the sum of each row and column generated by table(). Thus, the expected output is:
1 2 3 4
SSTR 43 34 20 27 124
SSA 23 28 25 0 76
Control 0 0 0 0 0
66 62 45 27
I am particularly interested in dplyr-solutions.
My data
y <- structure(list(treatment = structure(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, 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,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L), .Label = c("SSTR", "SSA", "Control"), class = "factor"),
WHO = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L,
2L, 3L, 3L, 3L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 4L,
4L, 1L, 4L, 1L, 2L, 1L, 4L, 1L, 1L, 1L, 1L, 2L, 4L, 1L, 2L,
1L, 4L, 1L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 4L,
4L, 2L, 1L, 2L, 2L, 4L, 4L, 4L, 2L, 4L, 1L, 4L, 4L, 2L, 4L,
4L, 3L, 4L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 3L, 2L, 2L,
2L, 3L, 2L, 3L, 1L, 2L, 3L, 3L, 3L, 1L, 2L, 1L, 2L, 3L, 3L,
1L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 1L, 3L, 1L, 3L, 3L, 2L, 3L, 1L, 1L, 2L, 1L,
1L, 3L, 2L, 1L, 1L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
2L, 2L, 2L, 2L, 3L, 2L, 3L, 2L, 1L, 2L, 3L, 2L, 2L, 2L, 1L,
3L, 3L, 3L, 2L, 3L, 2L, 3L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 1L, 1L), .Label = c("1",
"2", "3", "4"), class = "factor")), na.action = structure(c(`152` = 152L,
`193` = 193L), class = "omit"), row.names = 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, 52L, 53L, 54L, 55L, 56L, 57L,
58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L,
71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L,
84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L,
97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L,
108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L,
119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L,
130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L,
141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L, 150L, 151L,
153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L,
164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L,
175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L,
186L, 187L, 188L, 189L, 190L, 191L, 192L, 194L, 195L, 196L, 197L,
198L, 199L, 200L, 201L, 202L), class = "data.frame")
A possible solution to consider:
x<-table(y$treatment,y$WHO)
rowcoltotals <- addmargins(x, FUN = list(Total = sum), quiet = TRUE)
output:
1 2 3 4 Total
SSTR 43 34 20 27 124
SSA 23 28 25 0 76
Control 0 0 0 0 0
Total 66 62 45 27 200

How can I remove the legend from this boxplot in ggplot? [duplicate]

This question already has answers here:
Remove legend ggplot 2.2
(4 answers)
Closed 3 years ago.
Please find My Data below.
How can I remove the red, encircled legend from my boxplot?
I wish to keep the same colors and design. I have tried numerous different solutions, but this has unfortunately not solved the problem.
This might be kinda basic, but simply can't figure out how to solve this. I hope you can help - thanks in advance!
My script is:
df <- data.frame(x = as.factor(c(p$WHO.Grade)),
y = c(p$ki67pro),
f = rep(c("Ki67pro"), c(nrow(p))))
ggplot(df) +
geom_boxplot(aes(x, y, fill = f, colour = f), outlier.alpha = 0, position = position_dodge(width = 0.78)) +
scale_x_discrete(name = "", label=c("WHO-I\nn=108","WHO-II\nn=34","WHO-III\nn=1")) +
scale_y_continuous(name="Ki-67 proliferative index", breaks=seq(0,30,5), limits=c(0,30)) +
stat_boxplot(aes(x, y, colour = f), geom = "errorbar", width = 0.3,position = position_dodge(0.7753)) +
geom_point(aes(x, y, fill = f, colour = f), size = 3, shape = 21, position = position_jitterdodge()) +
scale_fill_manual(values = c("#52C1C76D"), name = "",
labels = c("\nTotal cohort\nn=159\n ")) +
scale_colour_manual(values = c("#51BFC4"), name = "",
labels = c("\nTotal cohort\nn=159\n "))
And My Data
p <- structure(list(WHO.Grade = c(1L, 2L, 1L, 1L, 1L, 1L, 3L, 2L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), ki67pro = c(1L, 12L, 3L, 3L, 5L,
3L, 20L, 25L, 7L, 4L, 5L, 12L, 3L, 15L, 4L, 5L, 7L, 8L, 3L, 12L,
10L, 4L, 10L, 7L, 3L, 2L, 3L, 7L, 4L, 7L, 10L, 4L, 5L, 5L, 3L,
5L, 2L, 5L, 3L, 3L, 3L, 4L, 4L, 3L, 2L, 5L, 1L, 5L, 2L, 3L, 1L,
2L, 3L, 3L, 5L, 4L, 20L, 5L, 0L, 4L, 3L, 0L, 3L, 4L, 1L, 2L,
20L, 2L, 3L, 5L, 4L, 8L, 1L, 4L, 5L, 4L, 3L, 6L, 12L, 3L, 4L,
4L, 2L, 5L, 3L, 3L, 3L, 2L, 5L, 4L, 2L, 3L, 4L, 3L, 3L, 2L, 2L,
4L, 7L, 4L, 3L, 4L, 2L, 3L, 6L, 2L, 3L, 10L, 5L, 10L, 3L, 10L,
3L, 4L, 5L, 2L, 4L, 3L, 4L, 4L, 4L, 5L, 3L, 12L, 5L, 4L, 3L,
2L, 4L, 3L, 4L, 2L, 1L, 6L, 1L, 4L, 12L, 3L, 4L, 3L, 2L, 6L,
5L, 4L, 3L, 4L, 4L, 4L, 3L, 5L, 4L, 5L, 4L, 1L, 3L, 3L, 4L, 0L,
3L)), class = "data.frame", row.names = c(1L, 2L, 3L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L,
53L, 54L, 55L, 57L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L,
68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L,
81L, 82L, 83L, 84L, 85L, 87L, 89L, 90L, 91L, 92L, 93L, 94L, 96L,
97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L,
109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L,
120L, 121L, 123L, 124L, 125L, 126L, 127L, 128L, 130L, 131L, 132L,
133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L,
144L, 145L, 146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L,
155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L,
166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L))
You can use theme() as follows:
... + theme(legend.position = "none")
This should eliminate the legend
reference: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/

Grouped Frequency Bars in R using ggplot

I'm trying to produce a bar graph with frequencies of multiple groups. I tried using geom_bar() but I keep running into "Error: stat_count() must not be used with a y aesthetic." I have one line for each participant, with age (2 categories), condition (2 categories), and their performance (0 or 1). From what I read on the manual and in pretty much everywhere online, if I use
bar<-ggplot(data, aes(age, performance, fill = condition)) + geom_bar(position = "dodge")
I should get what I want (which is this), but instead I get the error and I can't figure out what I'm missing. Isn't the geom_bar() supposed to give count by default? When I use stat="identity" I get full bars like so: how it actually looks.
Please help! Any advice will be greatly appreciated.
EDITED:
Here's my actual data:
structure(list(ageyears = c(4L, 4L, 5L, 5L, 5L, 4L, 5L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 4L, 5L, 4L, 5L, 4L, 5L,
4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 4L, 4L, 5L, 4L,
5L, 5L, 4L, 4L, 4L, 5L, 4L, 4L, 5L, 4L, 5L, 4L, 4L, 5L, 5L, 4L,
4L, 5L, 4L, 5L, 4L, 5L, 4L, 4L, 5L, 4L, 5L, 4L, 5L, 4L, 5L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 5L, 4L, 4L, 5L, 5L, 4L, 5L, 5L, 4L, 4L,
5L, 5L, 5L, 4L, 5L, 5L, 4L, 5L, 5L, 4L, 4L, 5L, 4L, 5L, 5L, 4L,
5L, 4L, 4L, 5L, 5L, 4L, 5L, 5L, 5L, 4L, 5L, 4L, 5L, 4L, 5L, 4L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1L, 0L, 0L, 0L, 0L, 1L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L,
1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L)), .Names = c("ageyears",
"MatrixLabels", "Mat_sort_pass_fail"), row.names = c(1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 11L, 12L, 13L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 48L,
49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 82L, 83L, 85L, 86L, 87L, 88L, 89L, 90L, 91L,
92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L,
104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L,
115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L,
126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L,
137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L,
148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L,
159L, 160L, 197L, 198L, 200L, 201L, 202L, 203L, 204L, 205L, 206L,
207L), class = "data.frame")
From the documentation of geom_bar :
By default, geom_bar uses stat="count" which makes the height of the
bar proportion to the number of cases in each group (or if the weight
aethetic is supplied, the sum of the weights). If you want the heights
of the bars to represent values in the data, use stat="identity" and
map a variable to the y aesthetic.
In your case you should use the height as your sum of your performance, since you have a summarized data , so the ggplot should use stat = identity
EDIT After OP pasted the dput:
You need to first summarize your data, I am assuming the df is your dataframe, you can use anything to do the summarization, I am using data.table and baseR aggregate, you can pick either of them to do it as below:
###1. base R aggregate
df <- aggregate(Mat_sort_pass_fail ~ ageyears + MatrixLabels, data=df1 ,sum)
df$perc <- df$Mat_sort_pass_fail/sum(df$Mat_sort_pass_fail)
names(df) <- c("age","condition","performance","percentage")
###2. sumarization using data.table
library(data.table)
dt <- setDT(df)
dt1 <- dt[,list(Performance = sum(Mat_sort_pass_fail)),by=c("ageyears","MatrixLabels")]
dt1[,perc:=Performance/sum(Performance)] ##percentage within column
df <- data.frame(dt1)
names(df) <- c("age","condition","performance","percentage")
library(ggplot2)
library(RColorBrewer)
ggplot(df, aes(x = condition ,y=performance)) +
geom_bar(aes(fill = factor(age)),stat="identity",position = "dodge") +
ggtitle("Matrix Sort Performance") +
scale_fill_brewer(palette = "Dark2")
###In case you need the percentage run the below code:
ggplot(df, aes(x = condition ,y=percentage)) +
geom_bar(aes(fill = factor(age)),stat="identity",position = "dodge") +
ggtitle("Matrix Sort Performance") +
scale_fill_brewer(palette = "Dark2")
Normally it calculates frquencies from your data. If your data is already grouped try below:
+ geom_bar(stat="identity",position = "dodge")
You can use geom_col() as an alias for geom_bar(stat = "identity").
You also had what I think is wrong aes mapping.
I mimicked some data based on the graph you posted:
df <- data.frame(age = factor(rep(4:5, each = 2), labels = c('4-Years-Olds', '5-Years-Olds')),
performance = c(48,37,65,65),
condition = factor(c(1,2,1,2), labels = c('No Label', 'Label')))
library(ggplot2)
ggplot(df) +
geom_col(aes(condition, performance, fill = age), position = 'dodge') +
scale_fill_manual(values = c('skyblue', 'darkolivegreen1'))

Calculating Variance Inflation Factors (VIFs) based on object type in R

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,
3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L, 4L, 3L, 4L, 4L, 3L, 3L, 4L,
4L, 4L), .Label = c("East", "Flat", "North", "South", "West"
), class = "factor"), height = c(515L, 60L, 60L, 30L, 70L,
70L, 40L, 70L, 50L, 75L, 160L, 85L, 40L, 90L, 70L, 210L,
30L, 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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.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).

Resources