Reputation: 340
I am getting the "NAs introduced by coercion" error, but I don't have any NAs
in my data set and my model should be fully specified as it is not very complicated. The issue is arising when I attempt to create a Daniel Plot using the DanielPlot()
function.
the linear model I used was simply
q4_model_1 = lm(data = HW3Q4, formula = Yield ~ A*B*C*D*E + Block, na.action = na.exclude)
For precaution I took the extra step of converting all of the necessary columns into factors (A,B,C,D,E and Block):
for (i in 1:5){
HW3Q4[ , i + 1] = as_factor(HW3Q4[ , i + 1])
}
HW3Q4$Block = as_factor(HW3Q4$Block)
Now using this I attempted to use the DanielPlot()
function found in the FrF2
package
DanielPlot(q4_model_1, half = FALSE)
But I get hit with the "NAs introduced by coercion". The data set is not that large and I include it below. I have a hunch it might be that since some of the factors are characters
that this may be the issue, but I'm on the fence because I was able to get regression coefficients and compute and anova()
from my model. And I specifically stated for the columns to be seen as factors. So this is more of a R programming issue for me than a comprehension of the concepts.
dput(HW3Q4)
structure(list(Unit = c(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), A = c("L", "H", "L", "H", "L", "H", "L", "H",
"L", "H", "L", "H", "L", "H", "L", "H", "L", "H", "L", "H", "L",
"H", "L", "H", "L", "H", "L", "H", "L", "H", "L", "H"), B = c(-1,
-1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1,
1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1), C = c(3, 3, 3,
3, 7, 7, 7, 7, 3, 3, 3, 3, 7, 7, 7, 7, 3, 3, 3, 3, 7, 7, 7, 7,
3, 3, 3, 3, 7, 7, 7, 7), D = c("S", "S", "S", "S", "S", "S",
"S", "S", "L", "L", "L", "L", "L", "L", "L", "L", "S", "S", "S",
"S", "S", "S", "S", "S", "L", "L", "L", "L", "L", "L", "L", "L"
), E = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Yield = c(11, 15,
62, 103, 28, 36, 74, 112, 13, 17, 58, 93, 32, 37, 81, 114, 13,
21, 64, 97, 26, 39, 83, 122, 10, 17, 55, 99, 26, 36, 76, 118),
Block = structure(c(1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L,
2L, 2L, 1L, 2L, 1L, 1L, 2L), .Label = c("0", "1"), class = "factor")), row.names = c(NA,
-32L), spec = structure(list(cols = list(Unit = structure(list(), class = c("collector_double",
"collector")), A = structure(list(), class = c("collector_character",
"collector")), B = structure(list(), class = c("collector_double",
"collector")), C = structure(list(), class = c("collector_double",
"collector")), D = structure(list(), class = c("collector_character",
"collector")), E = structure(list(), class = c("collector_double",
"collector")), Yield = structure(list(), class = c("collector_double",
"collector")), ...8 = structure(list(), class = c("collector_logical",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x0000026af40b0710>, class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
Upvotes: 0
Views: 146
Reputation: 340
I have a temporary solution. It would appear the "cute" for loop I tried to run to automate making my columns into factors did not do that. SO I had to manually turn my columns into factors. I could get away with it here because there are a small amount of columns. But I want to know what could I do if I had a larger data set where I could not do this manually?
Upvotes: 0