#-----------------------------------------------------------------------
# Prof. Dr. Walmes M. Zeviani
# leg.ufpr.br/~walmes · github.com/walmes
# walmes@ufpr.br · @walmeszeviani
# Laboratory of Statistics and Geoinformation (LEG)
# Department of Statistics · Federal University of Paraná
# 2020-set-25 · Curitiba/PR/Brazil
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Pacotes.
rm(list = objects())
library(lattice)
library(latticeExtra)
library(tidyverse)
my_palette <- colorRampPalette(
RColorBrewer::brewer.pal(n = 11, name = "Spectral"),
space = "rgb")
#-----------------------------------------------------------------------
# Importação.
# ATTENTION: tabela extraída de
# `Luciane Rozwalka.zip` > /Luciane Rozwalka/pessego/latencia.xls
tb <- read_tsv("chimarrita-maciel.txt",
locale = locale(decimal_mark = ","),
na = c("", "?"))
attr(tb, "spec") <- NULL
str(tb)
## spc_tbl_ [448 × 24] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ cultivar : chr [1:448] "maciel" "maciel" "maciel" "maciel" ...
## $ ferimento: chr [1:448] "sim" "sim" "sim" "sim" ...
## $ lado : chr [1:448] "inoculado" "inoculado" "inoculado" "inoculado" ...
## $ fruto : num [1:448] 1 2 3 4 5 6 7 8 9 10 ...
## $ cor0 : num [1:448] 91.1 92.1 110.1 103.2 100.9 ...
## $ ida0 : num [1:448] 1.45 1.09 2.08 1.18 1.75 0.33 1.26 1.36 2.08 1.64 ...
## $ ida48 : num [1:448] 1.19 0.68 2.17 NA 1.55 0.33 0.97 1.15 2.12 1.47 ...
## $ ida60 : num [1:448] 1.24 0.66 2.1 1.81 1.53 0.53 1.17 1.19 2.13 1.44 ...
## $ ms0 : num [1:448] 20.4 18.9 10.9 11.2 18 ...
## $ ms48 : num [1:448] 16.9 18.3 10.1 12 18.4 ...
## $ ms60 : num [1:448] 17.7 18.4 11.3 14.2 17.6 ...
## $ ss0 : num [1:448] 10.86 10.95 6.94 11.69 11.75 ...
## $ ss48 : num [1:448] 12.99 12.58 8.52 14.86 13.79 ...
## $ ss60 : num [1:448] 8.72 9.55 3.92 8.35 10.01 ...
## $ f0 : num [1:448] 5.79 4.46 8.79 7.2 7.44 3.19 4.67 5.76 7.7 6.28 ...
## $ f48 : num [1:448] 3.68 2.94 7.71 6.17 4.87 3.8 2.77 4.22 6.83 4.62 ...
## $ f60 : num [1:448] 4.72 3.21 8.22 7.47 5.92 4.77 5.58 6.56 7.59 6.8 ...
## $ b0 : num [1:448] 12.5 12.9 10.5 10.5 12.9 ...
## $ b48 : num [1:448] 11.74 12.45 9.86 10.32 11.75 ...
## $ b60 : num [1:448] 11.69 13.27 9.82 10.41 12.02 ...
## $ le48 : num [1:448] 5.42 2.03 5.11 NA 5.81 ...
## $ le60 : num [1:448] 19.5 14.2 21.5 20.2 23.7 ...
## $ la48 : num [1:448] 0 0 0 0 0 1 0 0 0 0 ...
## $ la60 : num [1:448] 0 0 0 0 0 1 0 0 0 1 ...
## - attr(*, "problems")=<externalptr>
# Inspeção.
ftable(xtabs(~cultivar + ferimento + lado, data = tb))
## lado inoculado não inoculado
## cultivar ferimento
## chimarrita não 56 56
## sim 56 56
## maciel não 56 56
## sim 56 56
# Dentro do fruto tem os lados inoculado e não inoculado.
tb %>%
filter(cultivar == "maciel",
ferimento == "sim",
fruto %in% 1:10) %>%
arrange(fruto, lado)
## # A tibble: 20 × 24
## culti…¹ ferim…² lado fruto cor0 ida0 ida48 ida60 ms0 ms48 ms60
## <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 maciel sim inoc… 1 91.1 1.45 1.19 1.24 20.4 17.0 17.7
## 2 maciel sim não … 1 98.2 1.29 1.1 0.9 17.4 17.7 15.7
## 3 maciel sim inoc… 2 92.1 1.09 0.68 0.66 18.9 18.3 18.4
## 4 maciel sim não … 2 92.6 0.97 0.76 0.66 19.9 19.0 18.0
## 5 maciel sim inoc… 3 110. 2.08 2.17 2.1 10.9 10.1 11.3
## 6 maciel sim não … 3 109. 2.17 2.13 2.07 9 10.7 10.5
## 7 maciel sim inoc… 4 103. 1.18 NA 1.81 11.2 12 14.2
## 8 maciel sim não … 4 107. 1.64 NA 1.86 12.6 14.2 13.4
## 9 maciel sim inoc… 5 101. 1.75 1.55 1.53 18 18.4 17.6
## 10 maciel sim não … 5 92.2 1.55 0.82 0.78 18.4 18.1 17.7
## 11 maciel sim inoc… 6 84.6 0.33 0.33 0.53 20.6 21.5 23.9
## 12 maciel sim não … 6 77.6 0.17 0.12 0.08 21.7 20.7 19.5
## 13 maciel sim inoc… 7 94.0 1.26 0.97 1.17 16.4 17.0 18.0
## 14 maciel sim não … 7 175. 1.41 1.03 0.98 17.9 17.5 16.5
## 15 maciel sim inoc… 8 94.0 1.36 1.15 1.19 17.5 18.2 18.0
## 16 maciel sim não … 8 105. 1.41 1.8 1.67 12.1 12.4 13.1
## 17 maciel sim inoc… 9 109. 2.08 2.12 2.13 14.5 13.6 10.2
## 18 maciel sim não … 9 107. 2.12 2.06 2.04 13.0 13.8 11.1
## 19 maciel sim inoc… 10 100. 1.64 1.47 1.44 11.2 14.8 16.8
## 20 maciel sim não … 10 103. 1.8 1.81 1.66 12.4 14.3 12.2
## # … with 13 more variables: ss0 <dbl>, ss48 <dbl>, ss60 <dbl>,
## # f0 <dbl>, f48 <dbl>, f60 <dbl>, b0 <dbl>, b48 <dbl>, b60 <dbl>,
## # le48 <dbl>, le60 <dbl>, la48 <dbl>, la60 <dbl>, and abbreviated
## # variable names ¹cultivar, ²ferimento
#-----------------------------------------------------------------------
# Recodificação.
tb <- tb %>%
mutate(ferimento = recode(ferimento,
"sim" = "W",
"não" = "noW"),
cultivar = recode(cultivar,
"chimarrita" = "Chimarrita",
"maciel" = "Maciel"),
lado = recode(lado,
"inoculado" = "Is",
"não inoculado" = "OsIs"))
tb %>%
count(cultivar, lado)
## # A tibble: 4 × 3
## cultivar lado n
## <chr> <chr> <int>
## 1 Chimarrita Is 112
## 2 Chimarrita OsIs 112
## 3 Maciel Is 112
## 4 Maciel OsIs 112
#-----------------------------------------------------------------------
# Análise gráfica.
# Empilha as variáveis.
tb_l <- tb %>%
pivot_longer(cols = -(cultivar:fruto),
names_to = "variable",
values_to = "value") %>%
# gather(key = "variable", value = "value", -(cultivar:fruto)) %>%
mutate(trat = sprintf("%s-%s:%s",
lado, ferimento, str_remove(variable, "\\D+")),
mea = str_remove(variable, "\\d+"),
tempo = as.integer(str_remove(variable, "\\D+")))
str(tb_l)
## tibble [8,960 × 9] (S3: tbl_df/tbl/data.frame)
## $ cultivar : chr [1:8960] "Maciel" "Maciel" "Maciel" "Maciel" ...
## $ ferimento: chr [1:8960] "W" "W" "W" "W" ...
## $ lado : chr [1:8960] "Is" "Is" "Is" "Is" ...
## $ fruto : num [1:8960] 1 1 1 1 1 1 1 1 1 1 ...
## $ variable : chr [1:8960] "cor0" "ida0" "ida48" "ida60" ...
## $ value : num [1:8960] 91.09 1.45 1.19 1.24 20.4 ...
## $ trat : chr [1:8960] "Is-W:0" "Is-W:0" "Is-W:48" "Is-W:60" ...
## $ mea : chr [1:8960] "cor" "ida" "ida" "ida" ...
## $ tempo : int [1:8960] 0 0 48 60 0 48 60 0 48 60 ...
# unique(tb_l$mea)
# Para recodificação.
v <- list(ida = "DA index",
ms = "Dry matter",
ss = "Titratable acidity",
f = "Firmness (N)",
b = "°Brix")
# Faz a recodificação.
tb_l <- tb_l %>%
mutate(mea = recode(mea, !!!v))
# unique(tb_l$mea)
# Compara os lados do fruto.
tb_side <- tb_l %>%
mutate(id = paste0(cultivar, fruto)) %>%
select(-trat) %>%
# spread(key = lado, value = value) %>%
pivot_wider(names_from = "lado", values_from = "value") %>%
mutate(d = Is - OsIs)
cap <- "Physicochemical characteristics (median, 25 and 75th percentile, minimum and maximum values excluding outliers and outliers) measured on inoculated side without wound (Is-noW), opposite side not inoculated of fruit without wound (OsIs-noW), inoculated side with wound (Is-W) and opposite side not inoculated of inoculated fruit with wound (OsIs-W) of ‘Chimarrita’ and ‘Maciel’ cultivars in postharvest using non-destructive methodology, in the moment of inoculation (time 0) and 48 and 60 h post inoculation. Pelotas, RS. Solid lines indicate mean trend for each combination of fruit side and wound."
# Apresenta os dados.
ggplot(data = filter(tb_l, is.element(mea, unlist(v))),
mapping = aes(x = trat, y = value)) +
facet_grid(facets = mea ~ cultivar,
scales = "free") +
geom_boxplot() +
stat_summary(mapping = aes(group = paste(lado, ferimento)),
geom = "line",
fun = "mean",
color = "red") +
labs(y = "Physicochemical characteristics\n(value)",
x = "Treatment:Time after inoculation (h)") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
Physicochemical characteristics (median, 25 and 75th percentile, minimum and maximum values excluding outliers and outliers) measured on inoculated side without wound (Is-noW), opposite side not inoculated of fruit without wound (OsIs-noW), inoculated side with wound (Is-W) and opposite side not inoculated of inoculated fruit with wound (OsIs-W) of ‘Chimarrita’ and ‘Maciel’ cultivars in postharvest using non-destructive methodology, in the moment of inoculation (time 0) and 48 and 60 h post inoculation. Pelotas, RS. Solid lines indicate mean trend for each combination of fruit side and wound.
O gráfico mostra que o efeito do tempo na média das variáveis é maior para a cultivar Chimarrita. Alterações nas variáveis são maiores para o lado do fruto inoculado e com ferimento.
cap <- "Difference in physicochemical properties (median, 25 and 75th percentile, minimum and maximum values excluding outliers and outliers) measured on the inoculated side with wound (Is-W) and opposite side not inoculated of inoculated fruit with wound (OsIs-W), of ‘Chimarrita’ and ‘Maciel’ cultivars in postharvest using non-destructive methodology, in the moment of inoculation (time 0) and 48 and 60 h post inoculation. Pelotas, RS, Brazil. Solid lines indicate mean trend."
# Visualiza as diferenças.
ggplot(data = filter(tb_side, is.element(mea, unlist(v))),
mapping = aes(x = paste(ferimento, tempo, sep = ":"),
y = d)) +
facet_grid(facets = mea ~ cultivar, scales = "free") +
geom_boxplot() +
stat_summary(mapping = aes(group = ferimento),
geom = "line",
fun = "mean",
color = "red") +
labs(y = "Physicochemical characteristics\n(difference between sides)",
x = "Wound:Time after inoculation (h)") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
Difference in physicochemical properties (median, 25 and 75th percentile, minimum and maximum values excluding outliers and outliers) measured on the inoculated side with wound (Is-W) and opposite side not inoculated of inoculated fruit with wound (OsIs-W), of ‘Chimarrita’ and ‘Maciel’ cultivars in postharvest using non-destructive methodology, in the moment of inoculation (time 0) and 48 and 60 h post inoculation. Pelotas, RS, Brazil. Solid lines indicate mean trend.
O gráfico mostra a diferença no valor das variáveis comparando os lados do fruto. Para os frutos sem ferimento, verifica-se não haver diferença nas variáveis comparando-se os lados. Por outro lado, para frutos com ferimento, observa-se diferença nas variáveis entre os lados. Nos frutos de chimarrita a alteração ocorre para todas as variáveis, exceto DA index. Para frutos de maciel, observa-se alteração apenas nas variáveis firmness e total soluble acidity.
cap <- "Physicochemical properties measured on wounded and no wounded fruits for combinations among cultivars, fruit side and time. Two sample t-test is used to test the effect wound (codification for the p-values: `*** < 0.001`, `** < 0.01`, `* < 0.05`, `. < 0.1` and `ns >= 0.1`). Pelotas, RS, Brazil."
# Teste t para comparar com vs sem ferimento.
u <- unique(tb_l$variable) |> head(n = -4)
tb_ttest <- tb_l %>%
filter(variable %in% u) %>%
mutate(lado_tempo = paste(lado, tempo, sep = ":")) %>%
group_by(cultivar, lado_tempo, variable) %>%
do({
tb_ttest <- . |>
rstatix::t_test(value ~ ferimento,
var.equal = TRUE,
detailed = TRUE,
p.adjust.method = "none")
tb_max <- . |>
summarise(max_value = extendrange(value, f = 0.1)[2])
bind_cols(tb_ttest, tb_max)
}) %>%
ungroup() %>%
left_join(distinct(tb_l, variable, mea))
## Joining with `by = join_by(variable)`
# str(tb_ttest)
tb_ttest <- tb_ttest %>%
mutate(p_signif = cut(p,
breaks = c(0, 0.001, 0.01, 0.05, 0.1, 1),
labels = c("***", "**", "*", ".", "ns")))
tb_l %>%
filter(mea %in% v) %>%
# filter(variable %in% u) %>%
mutate(lado_tempo = paste(lado, tempo, sep = ":")) %>%
ggpubr::ggboxplot(
x = "ferimento",
y = "value",
# x = "lado_tempo",
ggtheme = theme_gray()
) +
facet_grid(mea ~ cultivar + lado_tempo, scale = "free") +
ggpubr::stat_pvalue_manual(
filter(tb_ttest, mea %in% v),
# label = "p = {sprintf('%0.4f', p)}",
label = "p_signif",
y.position = "max_value") +
labs(y = "Physicochemical characteristics\n(value)",
x = "Treatment") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
Physicochemical properties measured on wounded and no wounded fruits for combinations among cultivars, fruit side and time. Two sample t-test is used to test the effect wound (codification for the p-values: *** < 0.001
, ** < 0.01
, * < 0.05
, . < 0.1
and ns >= 0.1
). Pelotas, RS, Brazil.
cap <- "Results from t-tests. Pelotas, RS, Brazil."
# Exibe.
tb_ttest |>
select(-c(".y.", "statistic", "df", "method",
"alternative", "max_value", "group1", "group2")) |>
relocate(c("cultivar", "mea", "variable", "lado_tempo",
"estimate1", "estimate2", "estimate")) |>
rename("noW_average" = "estimate1",
"W_average" = "estimate2",
"difference" = "estimate") |>
knitr::kable(caption = cap)
cultivar | mea | variable | lado_tempo | noW_average | W_average | difference | n1 | n2 | p | conf.low | conf.high | p_signif |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chimarrita | °Brix | b0 | Is:0 | 12.0153571 | 12.2223214 | -0.2069643 | 56 | 56 | 3.16e-01 | -0.6144274 | 0.2004989 | ns |
Chimarrita | cor | cor0 | Is:0 | 84.8576786 | 76.8185714 | 8.0391071 | 56 | 56 | 9.39e-02 | -1.3877303 | 17.4659446 | . |
Chimarrita | Firmness (N) | f0 | Is:0 | 5.7587500 | 5.6476786 | 0.1110714 | 56 | 56 | 4.33e-01 | -0.1685603 | 0.3907032 | ns |
Chimarrita | DA index | ida0 | Is:0 | 1.5003571 | 1.5264286 | -0.0260714 | 56 | 56 | 6.73e-01 | -0.1480501 | 0.0959073 | ns |
Chimarrita | Dry matter | ms0 | Is:0 | 9.7900000 | 11.6840000 | -1.8940000 | 51 | 45 | 2.34e-02 | -3.5259719 | -0.2620281 | * |
Chimarrita | Titratable acidity | ss0 | Is:0 | 7.1051786 | 7.2371429 | -0.1319643 | 56 | 56 | 5.96e-01 | -0.6238869 | 0.3599583 | ns |
Chimarrita | °Brix | b48 | Is:48 | 12.0332143 | 13.0457143 | -1.0125000 | 56 | 56 | 4.30e-06 | -1.4274021 | -0.5975979 | *** |
Chimarrita | Firmness (N) | f48 | Is:48 | 4.4303571 | 4.4616071 | -0.0312500 | 56 | 56 | 9.00e-01 | -0.5217227 | 0.4592227 | ns |
Chimarrita | DA index | ida48 | Is:48 | 1.1617857 | 1.0310714 | 0.1307143 | 56 | 56 | 1.72e-01 | -0.0575241 | 0.3189527 | ns |
Chimarrita | Dry matter | ms48 | Is:48 | 14.0969231 | 8.9516327 | 5.1452904 | 52 | 49 | 0.00e+00 | 3.9272296 | 6.3633512 | *** |
Chimarrita | Titratable acidity | ss48 | Is:48 | 7.0810714 | 4.2567857 | 2.8242857 | 56 | 56 | 0.00e+00 | 2.1848025 | 3.4637689 | *** |
Chimarrita | °Brix | b60 | Is:60 | 12.2950909 | 14.0380357 | -1.7429448 | 55 | 56 | 0.00e+00 | -2.1879182 | -1.2979714 | *** |
Chimarrita | Firmness (N) | f60 | Is:60 | 3.7990909 | 5.3201786 | -1.5210877 | 55 | 56 | 3.34e-04 | -2.3347544 | -0.7074209 | *** |
Chimarrita | DA index | ida60 | Is:60 | 0.9883929 | 0.8001786 | 0.1882143 | 56 | 56 | 4.37e-02 | 0.0053920 | 0.3710365 | * |
Chimarrita | Dry matter | ms60 | Is:60 | 14.3961538 | 5.5918605 | 8.8042934 | 52 | 43 | 0.00e+00 | 7.4481254 | 10.1604614 | *** |
Chimarrita | Titratable acidity | ss60 | Is:60 | 5.8698182 | -0.7089286 | 6.5787468 | 55 | 56 | 0.00e+00 | 5.5870348 | 7.5704587 | *** |
Chimarrita | °Brix | b0 | OsIs:0 | 12.0939286 | 12.1491071 | -0.0551786 | 56 | 56 | 7.90e-01 | -0.4643864 | 0.3540293 | ns |
Chimarrita | cor | cor0 | OsIs:0 | 68.6082143 | 78.1185714 | -9.5103571 | 56 | 56 | 1.02e-01 | -20.9517953 | 1.9310810 | ns |
Chimarrita | Firmness (N) | f0 | OsIs:0 | 5.8814286 | 5.5860714 | 0.2953571 | 56 | 56 | 6.63e-02 | -0.0201822 | 0.6108965 | . |
Chimarrita | DA index | ida0 | OsIs:0 | 1.4953571 | 1.4592857 | 0.0360714 | 56 | 56 | 5.65e-01 | -0.0879263 | 0.1600692 | ns |
Chimarrita | Dry matter | ms0 | OsIs:0 | 9.6528000 | 10.7947826 | -1.1419826 | 50 | 46 | 1.47e-01 | -2.6910400 | 0.4070748 | ns |
Chimarrita | Titratable acidity | ss0 | OsIs:0 | 7.1523214 | 7.2651786 | -0.1128571 | 56 | 56 | 6.91e-01 | -0.6743128 | 0.4485986 | ns |
Chimarrita | °Brix | b48 | OsIs:48 | 11.7946429 | 11.9261818 | -0.1315390 | 56 | 55 | 4.79e-01 | -0.4981739 | 0.2350960 | ns |
Chimarrita | Firmness (N) | f48 | OsIs:48 | 4.2205357 | 4.0905455 | 0.1299903 | 56 | 55 | 5.78e-01 | -0.3312406 | 0.5912211 | ns |
Chimarrita | DA index | ida48 | OsIs:48 | 1.0833929 | 1.0589286 | 0.0244643 | 56 | 56 | 8.00e-01 | -0.1662120 | 0.2151406 | ns |
Chimarrita | Dry matter | ms48 | OsIs:48 | 12.8978846 | 12.4891667 | 0.4087179 | 52 | 48 | 4.53e-01 | -0.6676814 | 1.4851173 | ns |
Chimarrita | Titratable acidity | ss48 | OsIs:48 | 6.9148214 | 6.8434545 | 0.0713669 | 56 | 55 | 8.26e-01 | -0.5686643 | 0.7113980 | ns |
Chimarrita | °Brix | b60 | OsIs:60 | 11.8705357 | 12.1116071 | -0.2410714 | 56 | 56 | 2.36e-01 | -0.6420101 | 0.1598673 | ns |
Chimarrita | Firmness (N) | f60 | OsIs:60 | 3.4601786 | 3.2469643 | 0.2132143 | 56 | 56 | 4.34e-01 | -0.3251204 | 0.7515490 | ns |
Chimarrita | DA index | ida60 | OsIs:60 | 0.8732143 | 0.8360714 | 0.0371429 | 56 | 56 | 7.02e-01 | -0.1547506 | 0.2290363 | ns |
Chimarrita | Dry matter | ms60 | OsIs:60 | 13.4521154 | 11.8605882 | 1.5915271 | 52 | 51 | 1.29e-02 | 0.3439309 | 2.8391234 | * |
Chimarrita | Titratable acidity | ss60 | OsIs:60 | 6.0019643 | 5.4566071 | 0.5453571 | 56 | 56 | 1.47e-01 | -0.1939043 | 1.2846186 | ns |
Maciel | °Brix | b0 | Is:0 | 11.5394643 | 11.6812500 | -0.1417857 | 56 | 56 | 5.41e-01 | -0.5996863 | 0.3161149 | ns |
Maciel | cor | cor0 | Is:0 | 97.6207143 | 102.0453571 | -4.4246429 | 56 | 56 | 1.88e-01 | -11.0452845 | 2.1959988 | ns |
Maciel | Firmness (N) | f0 | Is:0 | 5.6076786 | 6.0569643 | -0.4492857 | 56 | 56 | 1.37e-01 | -1.0436703 | 0.1450988 | ns |
Maciel | DA index | ida0 | Is:0 | 1.4944643 | 1.5439286 | -0.0494643 | 56 | 56 | 5.63e-01 | -0.2185050 | 0.1195764 | ns |
Maciel | Dry matter | ms0 | Is:0 | 15.4103571 | 15.1539286 | 0.2564286 | 56 | 56 | 6.62e-01 | -0.9023286 | 1.4151857 | ns |
Maciel | Titratable acidity | ss0 | Is:0 | 11.9983929 | 11.2857143 | 0.7126786 | 56 | 56 | 2.43e-02 | 0.0943954 | 1.3309617 | * |
Maciel | °Brix | b48 | Is:48 | 11.5564286 | 11.3334545 | 0.2229740 | 56 | 55 | 3.38e-01 | -0.2365768 | 0.6825249 | ns |
Maciel | Firmness (N) | f48 | Is:48 | 5.4596429 | 4.5625000 | 0.8971429 | 56 | 56 | 1.02e-02 | 0.2167459 | 1.5775398 | * |
Maciel | DA index | ida48 | Is:48 | 1.3451786 | 1.3900000 | -0.0448214 | 56 | 55 | 6.72e-01 | -0.2541540 | 0.1645111 | ns |
Maciel | Dry matter | ms48 | Is:48 | 18.0621429 | 16.0046429 | 2.0575000 | 56 | 56 | 1.29e-03 | 0.8233530 | 3.2916470 | ** |
Maciel | Titratable acidity | ss48 | Is:48 | 12.1539286 | 12.8850000 | -0.7310714 | 56 | 56 | 5.03e-02 | -1.4631762 | 0.0010334 | . |
Maciel | °Brix | b60 | Is:60 | 11.6544643 | 12.0346429 | -0.3801786 | 56 | 56 | 1.08e-01 | -0.8450329 | 0.0846757 | ns |
Maciel | Firmness (N) | f60 | Is:60 | 3.8860714 | 5.9532143 | -2.0671429 | 56 | 56 | 1.00e-07 | -2.7790645 | -1.3552212 | *** |
Maciel | DA index | ida60 | Is:60 | 1.2400000 | 1.3328571 | -0.0928571 | 56 | 56 | 3.58e-01 | -0.2922401 | 0.1065258 | ns |
Maciel | Dry matter | ms60 | Is:60 | 15.3675000 | 16.2160714 | -0.8485714 | 56 | 56 | 1.69e-01 | -2.0632800 | 0.3661371 | ns |
Maciel | Titratable acidity | ss60 | Is:60 | 14.6882143 | 7.8021429 | 6.8860714 | 56 | 56 | 0.00e+00 | 5.6835835 | 8.0885594 | *** |
Maciel | °Brix | b0 | OsIs:0 | 11.6016071 | 11.4494643 | 0.1521429 | 56 | 56 | 5.45e-01 | -0.3441037 | 0.6483894 | ns |
Maciel | cor | cor0 | OsIs:0 | 100.2151786 | 102.5873214 | -2.3721429 | 56 | 56 | 6.09e-01 | -11.5347603 | 6.7904746 | ns |
Maciel | Firmness (N) | f0 | OsIs:0 | 5.6291071 | 5.8641071 | -0.2350000 | 56 | 56 | 4.40e-01 | -0.8362033 | 0.3662033 | ns |
Maciel | DA index | ida0 | OsIs:0 | 1.4783929 | 1.4626786 | 0.0157143 | 56 | 56 | 8.68e-01 | -0.1712112 | 0.2026397 | ns |
Maciel | Dry matter | ms0 | OsIs:0 | 15.3221429 | 14.9132143 | 0.4089286 | 56 | 56 | 5.09e-01 | -0.8153499 | 1.6332071 | ns |
Maciel | Titratable acidity | ss0 | OsIs:0 | 12.0133929 | 11.5296429 | 0.4837500 | 56 | 56 | 1.26e-01 | -0.1379925 | 1.1054925 | ns |
Maciel | °Brix | b48 | OsIs:48 | 11.1478571 | 10.6908929 | 0.4569643 | 56 | 56 | 7.46e-02 | -0.0460832 | 0.9600118 | . |
Maciel | Firmness (N) | f48 | OsIs:48 | 5.3042857 | 4.1794643 | 1.1248214 | 56 | 56 | 1.21e-03 | 0.4541479 | 1.7954949 | ** |
Maciel | DA index | ida48 | OsIs:48 | 1.3228571 | 1.3370909 | -0.0142338 | 56 | 55 | 8.94e-01 | -0.2259688 | 0.1975013 | ns |
Maciel | Dry matter | ms48 | OsIs:48 | 17.7314286 | 15.5273214 | 2.2041071 | 56 | 56 | 2.16e-04 | 1.0627140 | 3.3455003 | *** |
Maciel | Titratable acidity | ss48 | OsIs:48 | 11.5387500 | 13.4658929 | -1.9271429 | 56 | 56 | 1.00e-07 | -2.5902668 | -1.2640189 | *** |
Maciel | °Brix | b60 | OsIs:60 | 11.0925000 | 10.8875000 | 0.2050000 | 56 | 56 | 3.91e-01 | -0.2664532 | 0.6764532 | ns |
Maciel | Firmness (N) | f60 | OsIs:60 | 3.6551786 | 3.9914286 | -0.3362500 | 56 | 56 | 3.35e-01 | -1.0247461 | 0.3522461 | ns |
Maciel | DA index | ida60 | OsIs:60 | 1.2430909 | 1.3049091 | -0.0618182 | 55 | 55 | 5.80e-01 | -0.2825519 | 0.1589156 | ns |
Maciel | Dry matter | ms60 | OsIs:60 | 15.1580357 | 14.7846429 | 0.3733929 | 56 | 56 | 5.06e-01 | -0.7348816 | 1.4816673 | ns |
Maciel | Titratable acidity | ss60 | OsIs:60 | 14.1375000 | 13.5466071 | 0.5908929 | 56 | 56 | 1.05e-01 | -0.1249209 | 1.3067066 | ns |
# Mais recodificação.
v <- c("cor" = "Color (nm)",
"le" = "Lesion size (mm)")
# Faz a recodificação.
tb_l <- tb_l %>%
mutate(mea = recode(mea, !!!v))
# Medidas resumo.
tb_desc <- tb_l %>%
filter(lado == "Is", str_detect(mea, "^[A-Z]")) %>%
group_by(cultivar, ferimento, tempo, mea) %>%
summarise_at("value", c("mean", "min", "max"), na.rm = TRUE)
# Lista para guardar as tabelas parciais.
tb_summary <- list()
# Variáveis numéricas.
tb_summary[[1]] <- tb_desc %>%
mutate(string = sprintf("%0.1f (%0.1f; %0.1f)", mean, min, max)) %>%
unite(col = "cond", cultivar, ferimento, sep = " ") %>%
select(mea, tempo, cond, string) %>%
spread(key = cond, value = string)
# Aparecimento de lesão (incidência).
tb_summary[[2]] <- tb_l %>%
filter(lado == "Is", str_detect(mea, "Lesion")) %>%
group_by(cultivar, ferimento, tempo) %>%
summarise_at("value",
function(x) {
u <- sum(x > 0, na.rm = TRUE)
sprintf("%0.1f%% (%d/%d)",
100 * u/length(x),
u,
length(x))
}) %>%
unite(col = "cond", cultivar, ferimento, sep = " ") %>%
select(tempo, cond, value) %>%
spread(key = cond, value = value) %>%
add_column(mea = "Fruits with lesions", .before = 1)
# Esporulação (latência).
tb_summary[[3]] <- tb_l %>%
filter(lado == "Is", mea == "la") %>%
group_by(cultivar, ferimento, tempo) %>%
summarise_at("value",
function(x) {
u <- sum(x > 0, na.rm = TRUE)
sprintf("%0.1f%% (%d/%d)",
100 * u/length(x),
u,
length(x))
}) %>%
unite(col = "cond", cultivar, ferimento, sep = " ") %>%
select(tempo, cond, value) %>%
spread(key = cond, value = value) %>%
add_column(mea = "Sporulated lesions", .before = 1)
# Junta as tabelas e renomeia variáveis.
tb_summary <- tb_summary %>%
bind_rows() %>%
rename("Variable" = "mea", "Time (h)" = "tempo")
cap <- "Physicochemical characteristics (medium, minimum and maximum values) and severity, incidence and latent period of *Monilinia fructicola* in wounded and not wounded fruit of ‘Chimarrita’ and ‘Maciel’ cultivar at postharvest period. Pelotas, RS, Brazil."
# Exibe.
knitr::kable(tb_summary, caption = cap)
Variable | Time (h) | Chimarrita noW | Chimarrita W | Maciel noW | Maciel W |
---|---|---|---|---|---|
Color (nm) | 0 | 84.9 (38.2; 112.1) | 76.8 (24.7; 111.8) | 97.6 (75.7; 111.8) | 102.0 (74.0; 264.9) |
DA index | 0 | 1.5 (0.5; 2.1) | 1.5 (0.9; 2.1) | 1.5 (0.6; 2.1) | 1.5 (0.3; 2.1) |
DA index | 48 | 1.2 (0.2; 2.1) | 1.0 (0.3; 2.1) | 1.3 (0.3; 2.3) | 1.4 (0.3; 2.2) |
DA index | 60 | 1.0 (0.2; 2.1) | 0.8 (0.2; 1.9) | 1.2 (0.3; 2.1) | 1.3 (0.4; 2.2) |
Dry matter | 0 | 9.8 (0.6; 16.2) | 11.7 (1.3; 18.0) | 15.4 (8.1; 19.8) | 15.2 (5.8; 20.6) |
Dry matter | 48 | 14.1 (5.4; 19.3) | 9.0 (0.7; 16.1) | 18.1 (10.3; 24.9) | 16.0 (7.3; 21.5) |
Dry matter | 60 | 14.4 (1.4; 19.0) | 5.6 (0.2; 16.4) | 15.4 (6.3; 20.8) | 16.2 (7.9; 23.9) |
Firmness (N) | 0 | 5.8 (3.0; 6.7) | 5.6 (3.6; 6.7) | 5.6 (3.0; 9.1) | 6.1 (3.0; 9.3) |
Firmness (N) | 48 | 4.4 (1.4; 6.3) | 4.5 (-0.6; 8.2) | 5.5 (3.1; 10.0) | 4.6 (1.4; 8.8) |
Firmness (N) | 60 | 3.8 (1.2; 6.5) | 5.3 (-0.1; 12.6) | 3.9 (1.4; 8.5) | 6.0 (1.9; 11.9) |
Lesion size (mm) | 48 | 0.0 (0.0; 0.0) | 29.4 (24.8; 33.0) | 0.0 (0.0; 0.0) | 7.4 (0.0; 16.7) |
Lesion size (mm) | 60 | 0.0 (0.0; 0.0) | 44.2 (37.7; 49.1) | 0.0 (0.0; 0.0) | 21.4 (0.0; 33.8) |
Titratable acidity | 0 | 7.1 (4.3; 10.3) | 7.2 (3.9; 10.3) | 12.0 (6.2; 15.0) | 11.3 (6.9; 13.8) |
Titratable acidity | 48 | 7.1 (4.6; 11.5) | 4.3 (1.1; 8.9) | 12.2 (7.4; 15.3) | 12.9 (6.4; 16.8) |
Titratable acidity | 60 | 5.9 (3.4; 10.3) | -0.7 (-8.5; 7.2) | 14.7 (6.5; 17.8) | 7.8 (-2.2; 15.6) |
Fruits with lesions | 48 | 0.0% (0/56) | 100.0% (56/56) | 0.0% (0/56) | 89.3% (50/56) |
Fruits with lesions | 60 | 0.0% (0/56) | 100.0% (56/56) | 0.0% (0/56) | 96.4% (54/56) |
Sporulated lesions | 48 | 0.0% (0/56) | 32.1% (18/56) | 0.0% (0/56) | 1.8% (1/56) |
Sporulated lesions | 60 | 0.0% (0/56) | 100.0% (56/56) | 0.0% (0/56) | 7.1% (4/56) |
Lesion size data was submitted to linear regression as variable dependent. Soluble solids content, DA index, titratable acidity, pulp firmness and dry matter were used as independent variables, as also its first order interactions (\(p = 21\) variables, \(n = 56\)). Variable selections were performed by stepwise procedure based on the Akaike Information Criterion (AIC) using \(k = 3.84\) that is the 95th quantile of a chi-square random variable with 1 degree of freedom . This makes selection variables being performed at a 5% significance level using likelihood ratio tests. The mean lesion size was predicted with the selected independent variables.
Latency was submitted to generalized linear regression assuming binomial distribution, as it is a dichotomous response variable (0 or 1). This is also known as logistic regression. The same variables were used as independent variable and selected using stepwise procedure based on the AIC with \(k = 3.84\). To prevent over fitting, since a dichotomous is less informative than a continous variable, only main effects terms were used (\(p = 6\) variables, \(n = 56\)). The probability about sporulated lesions was predicted with the selected independent variables.
All statistical procedures were done using a 0.05 nominal significance level. Statistical analysis was performed using the R software (R Core Team 2020).
Incluir como referência biliográfica:
R Core Team (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.
# Seleciona recorte de interesse.
tb_reg <- tb %>%
filter(cultivar == "Chimarrita", ferimento == "W", lado == "Is") %>%
select(matches("[a-z]0"), le48, le60)
# Conta os valores ausentes.
tb_reg %>%
summarise_all(~sum(is.na(.)))
## # A tibble: 1 × 8
## cor0 ida0 ms0 ss0 f0 b0 le48 le60
## <int> <int> <int> <int> <int> <int> <int> <int>
## 1 0 0 11 0 0 0 0 0
# Análise exploratória.
tb_reg %>%
gather(key = "pred", value = "value", 1:6) %>%
ggplot(mapping = aes(x = value, y = le60)) +
facet_wrap(facets = ~pred, scale = "free_x") +
geom_point() +
geom_smooth(se = FALSE, color = "gray40") +
labs(x = "Variável independente",
y = "Tamanho da lesão")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
# O modelo saturado com termos de primeira e segunda ordem.
m0 <- lm(le60 ~ (.)^2, data = select(tb_reg, -le48))
summary(m0)
##
## Call:
## lm(formula = le60 ~ (.)^2, data = select(tb_reg, -le48))
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.660 -1.095 -0.019 1.151 4.655
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 14.417965 113.790988 0.127 0.900
## cor0 -0.100425 0.415863 -0.241 0.811
## ida0 80.314245 97.846660 0.821 0.420
## ms0 0.776230 5.575387 0.139 0.890
## ss0 -5.499361 14.524228 -0.379 0.708
## f0 -18.150884 36.111788 -0.503 0.620
## b0 6.655332 9.752256 0.682 0.502
## cor0:ida0 0.062521 0.160134 0.390 0.700
## cor0:ms0 0.011533 0.009462 1.219 0.235
## cor0:ss0 -0.021260 0.031717 -0.670 0.509
## cor0:f0 0.027501 0.068893 0.399 0.693
## cor0:b0 -0.010656 0.033846 -0.315 0.756
## ida0:ms0 -0.361286 1.400180 -0.258 0.799
## ida0:ss0 -3.148286 6.746582 -0.467 0.645
## ida0:f0 2.852293 8.168038 0.349 0.730
## ida0:b0 -5.693814 7.833365 -0.727 0.475
## ms0:ss0 -0.454088 0.526190 -0.863 0.397
## ms0:f0 0.866997 1.275913 0.680 0.504
## ms0:b0 -0.188244 0.320390 -0.588 0.563
## ss0:f0 1.177671 2.042980 0.576 0.570
## ss0:b0 0.864472 1.530276 0.565 0.578
## f0:b0 -0.482836 1.646729 -0.293 0.772
##
## Residual standard error: 2.234 on 23 degrees of freedom
## (11 observations deleted due to missingness)
## Multiple R-squared: 0.4762, Adjusted R-squared: -0.001969
## F-statistic: 0.9959 on 21 and 23 DF, p-value: 0.5012
# Aplica o stepwise para selecionar variáveis.
# Aqui usa-se AIC com k = 3.84.
m1 <- step(update(m0, data = m0$model),
k = qchisq(0.95, df = 1),
trace = 0,
data = m0$model)
summary(m1)
##
## Call:
## lm(formula = le60 ~ cor0 + ms0 + ss0 + b0 + cor0:ms0, data = m0$model)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.6754 -1.2921 0.2102 1.3962 4.0627
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 54.009190 5.126397 10.536 5.72e-13 ***
## cor0 -0.089881 0.040391 -2.225 0.0319 *
## ms0 -0.293178 0.283065 -1.036 0.3067
## ss0 1.011585 0.388371 2.605 0.0129 *
## b0 -1.018524 0.370448 -2.749 0.0090 **
## cor0:ms0 0.008129 0.003374 2.409 0.0208 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.982 on 39 degrees of freedom
## Multiple R-squared: 0.3009, Adjusted R-squared: 0.2112
## F-statistic: 3.357 on 5 and 39 DF, p-value: 0.01287
# Testa o não comprometimento dos termos abandonados.
anova(m0, m1)
## Analysis of Variance Table
##
## Model 1: le60 ~ (cor0 + ida0 + ms0 + ss0 + f0 + b0)^2
## Model 2: le60 ~ cor0 + ms0 + ss0 + b0 + cor0:ms0
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 23 114.78
## 2 39 153.21 -16 -38.43 0.4813 0.9321
par(mfrow = c(2, 2))
plot(m1); layout(1)
O modelo obtido com stepwise contém 4 variáveis, incluindo a interação entre um par delas. 11 observações foram eliminadas por causa de valores ausentes na variáveis ms0
. Então o modelo foi ajustado com 45.
Apesar do baixo \(R^2\), o efeito das variáveis é significativo a 5%. O baixo \(R^2\) apenas indica que tais variáveis explicam uma pequena porção da variabilidade total.
Não observou-se nenhum afastamento dos pressupostos do modelo de regressão por meio da análise gráfica dos resíduos.
O sinal dos coeficientes estimados indica se o efeito da variável é positivo ou negativo no tamanho da lesão. Cuidado ao interpretar efeitos principais de variáveis envolvidas em interações.
# Prepara malha para a predição.
# summary(m1$model)
tb_pred <- with(m1$model,
crossing(cor0 = seq(min(cor0), max(cor0), length.out = 24),
ms0 = seq(min(ms0), max(ms0), length.out = 24),
b0 = c(11, 12, 13),
ss0 = c(5, 6, 7)))
str(tb_pred)
## tibble [5,184 × 4] (S3: tbl_df/tbl/data.frame)
## $ cor0: num [1:5184] 24.7 24.7 24.7 24.7 24.7 ...
## $ ms0 : num [1:5184] 1.31 1.31 1.31 1.31 1.31 ...
## $ b0 : num [1:5184] 11 11 11 12 12 12 13 13 13 11 ...
## $ ss0 : num [1:5184] 5 6 7 5 6 7 5 6 7 5 ...
# Predição de cada ponto.
tb_pred$fit <- predict(m1, newdata = tb_pred)
cap <- "Lesion size at 60 h for wounded inoculated fruits predicted as a function of variables measured at inoculation (0 h) and select by stepwise procedure to Maciel cultivar."
# Gráfico de contornos de nível.
ggplot(data = tb_pred,
mapping = aes(x = cor0, y = ms0, fill = fit)) +
facet_grid(facets = b0 ~ ss0) +
geom_tile() +
geom_contour(mapping = aes(z = fit), color = "black") +
scale_fill_distiller(palette = "Spectral") +
labs(x = "Color",
y = "Dry matter",
fill = "Lesion\nsize (mm)",
title = "°Brix (rows) x Titratable acidity (columns)")
Lesion size at 60 h for wounded inoculated fruits predicted as a function of variables measured at inoculation (0 h) and select by stepwise procedure to Maciel cultivar.
# Gráfico 3D.
useOuterStrips(
wireframe(fit ~ cor0 + ms0 | factor(ss0) + factor(b0),
data = tb_pred,
drape = TRUE, col.regions = my_palette(90),
scales = list(arrows = FALSE),
par.settings = list(strip.background =
list(col = c("gray90","gray50")),
par.main.text = list(font = 1,
just = "left",
x = grid::unit(10, "mm"))),
main = list("°Brix (rows) x Titratable acidity (columns)"),
xlab = list("Color", rot = 30),
ylab = list("Dry matter", rot = -40),
zlab = list("Lesion size", rot = 90)))
Lesion size at 60 h for wounded inoculated fruits predicted as a function of variables measured at inoculation (0 h) and select by stepwise procedure to Maciel cultivar.
Os gráficos mostram que os maiores tamanho de lesão são esperados para a combinação de valores altos de dry matter com valores altos de color. Mantida as demais variáveis contantes, o aumento de total soluble solids diminui o tamanho de lesão enquanto que o aumento de brix provoca aumento no tamanho da lesão.
# Seleciona recorte de interesse.
tb_reg <- tb %>%
filter(cultivar == "Maciel", ferimento == "W", lado == "Is") %>%
mutate(cor0 = if_else(cor0 > 150, NA_real_, cor0)) %>%
select(matches("[a-z]0"), le48, le60)
# Conta os valores ausentes.
tb_reg %>%
summarise_all(~sum(is.na(.)))
## # A tibble: 1 × 8
## cor0 ida0 ms0 ss0 f0 b0 le48 le60
## <int> <int> <int> <int> <int> <int> <int> <int>
## 1 1 0 0 0 0 0 1 0
# Análise exploratória.
tb_reg %>%
gather(key = "pred", value = "value", 1:6) %>%
ggplot(mapping = aes(x = value, y = le60)) +
facet_wrap(facets = ~pred, scale = "free_x") +
geom_point() +
geom_smooth(se = FALSE, color = "gray40") +
labs(x = "Variável independente",
y = "Tamanho da lesão")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
# O modelo saturado com termos de primeira e segunda ordem.
m0 <- lm(le60 ~ (.)^2, data = select(tb_reg, -le48))
summary(m0)
##
## Call:
## lm(formula = le60 ~ (.)^2, data = select(tb_reg, -le48))
##
## Residuals:
## Min 1Q Median 3Q Max
## -16.594 -3.728 1.204 4.750 11.392
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.249e+02 5.302e+02 0.613 0.5443
## cor0 -3.255e+00 5.146e+00 -0.632 0.5314
## ida0 6.992e+02 2.765e+02 2.529 0.0164 *
## ms0 1.526e+00 2.200e+01 0.069 0.9451
## ss0 -2.991e+01 3.433e+01 -0.871 0.3899
## f0 -1.786e+02 8.014e+01 -2.229 0.0327 *
## b0 3.059e+00 5.138e+01 0.060 0.9529
## cor0:ida0 -4.729e+00 2.063e+00 -2.293 0.0284 *
## cor0:ms0 5.955e-02 2.090e-01 0.285 0.7775
## cor0:ss0 1.050e-01 2.792e-01 0.376 0.7092
## cor0:f0 1.418e+00 5.854e-01 2.423 0.0211 *
## cor0:b0 1.379e-02 5.077e-01 0.027 0.9785
## ida0:ms0 -1.113e+01 4.501e+00 -2.473 0.0187 *
## ida0:ss0 3.988e+00 6.868e+00 0.581 0.5654
## ida0:f0 -5.590e+00 5.451e+00 -1.026 0.3126
## ida0:b0 -8.047e+00 7.120e+00 -1.130 0.2665
## ms0:ss0 5.896e-01 6.676e-01 0.883 0.3836
## ms0:f0 2.164e+00 1.482e+00 1.460 0.1537
## ms0:b0 -7.514e-01 7.464e-01 -1.007 0.3214
## ss0:f0 6.265e-03 1.498e+00 0.004 0.9967
## ss0:b0 4.486e-01 1.291e+00 0.347 0.7305
## f0:b0 1.606e+00 2.867e+00 0.560 0.5792
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.464 on 33 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.3728, Adjusted R-squared: -0.02638
## F-statistic: 0.9339 on 21 and 33 DF, p-value: 0.5564
# Aplica o stepwise para selecionar variáveis.
# Aqui usa-se AIC com k = 3.84.
m1 <- step(update(m0, data = m0$model),
k = qchisq(0.95, df = 1),
trace = 0,
data = m0$model)
summary(m1)
##
## Call:
## lm(formula = le60 ~ 1, data = m0$model)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.237 -4.742 1.723 6.373 12.603
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 21.237 1.127 18.85 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.355 on 54 degrees of freedom
# Testa o não comprometimento dos termos abandonados.
anova(m0, m1)
## Analysis of Variance Table
##
## Model 1: le60 ~ (cor0 + ida0 + ms0 + ss0 + f0 + b0)^2
## Model 2: le60 ~ 1
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 33 2364.4
## 2 54 3769.5 -21 -1405.1 0.9339 0.5564
Para a cultivar Maciel, não se conseguiu modelo útil. O procedimento stepwise saiu do modelo saturado (\(p = 21\)) e obteve o modelo nulo (aapenas intercepto). Portanto, nenhum dos modelos avaliados superou significativamente o modelo nulo. Dessa forma, não foi possível detectar efeito das variáveis independentes no tamanho de lesão para a cultivar Maciel. Há pelo duas razões para a falha na detecção de efeito (caso ele exista): 1) o tamanho de amostra não foi suficiente e 2) as variáveis preditoras apresentaram valores numa faixa estreita do domínio que não permite “capturar o sinal” de seu efeito na resposta. Em futuros experimentos pode-se aumentar o tamanho de amostra e priorizar a seleção de frutos com valores mais extremos nas variáveis preditoras para ampliar o domínio observado delas.
# Seleciona recorte de interesse.
tb_reg <- tb %>%
filter(cultivar == "Chimarrita", ferimento == "W", lado == "Is") %>%
select(matches("[a-z]0"), la48, la60)
# Conta os valores ausentes.
tb_reg %>%
summarise_all(~sum(is.na(.)))
## # A tibble: 1 × 8
## cor0 ida0 ms0 ss0 f0 b0 la48 la60
## <int> <int> <int> <int> <int> <int> <int> <int>
## 1 0 0 11 0 0 0 0 0
# Análise exploratória.
tb_reg %>%
gather(key = "pred", value = "value", 1:6) %>%
ggplot(mapping = aes(x = value, y = la48)) +
facet_wrap(facets = ~pred, scale = "free_x") +
geom_point() +
geom_smooth(se = FALSE, color = "gray40") +
labs(x = "Variável independente",
y = "Tamanho da lesão")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
# Resumo descritivo.
summary(tb_reg)
## cor0 ida0 ms0 ss0
## Min. : 24.66 Min. :0.870 Min. : 1.31 Min. : 3.880
## 1st Qu.: 50.17 1st Qu.:1.278 1st Qu.:10.23 1st Qu.: 6.133
## Median : 80.65 Median :1.480 Median :12.04 Median : 7.200
## Mean : 76.82 Mean :1.526 Mean :11.68 Mean : 7.237
## 3rd Qu.:105.59 3rd Qu.:1.752 3rd Qu.:14.18 3rd Qu.: 8.002
## Max. :111.79 Max. :2.100 Max. :17.96 Max. :10.340
## NA's :11
## f0 b0 la48 la60
## Min. :3.560 Min. : 9.41 Min. :0.0000 Min. :1
## 1st Qu.:5.435 1st Qu.:11.54 1st Qu.:0.0000 1st Qu.:1
## Median :5.740 Median :12.21 Median :0.0000 Median :1
## Mean :5.648 Mean :12.22 Mean :0.3214 Mean :1
## 3rd Qu.:6.085 3rd Qu.:12.79 3rd Qu.:1.0000 3rd Qu.:1
## Max. :6.730 Max. :14.60 Max. :1.0000 Max. :1
##
# Frequências da resposta.
tb_reg %>%
count(la48, la60)
## # A tibble: 2 × 3
## la48 la60 n
## <dbl> <dbl> <int>
## 1 0 1 38
## 2 1 1 18
# O modelo saturado com termos de primeira ordem.
# Para prevenir over fitting, usou-se apenas termos de primeira ordem.
m0 <- glm(la48 ~ .,
family = binomial,
data = select(tb_reg, -la60))
summary(m0)
##
## Call:
## glm(formula = la48 ~ ., family = binomial, data = select(tb_reg,
## -la60))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.7493 -0.5315 -0.1571 0.5991 2.8952
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 17.27344 7.46018 2.315 0.02059 *
## cor0 0.03543 0.02167 1.635 0.10211
## ida0 -7.57770 4.65720 -1.627 0.10372
## ms0 0.66842 0.29587 2.259 0.02387 *
## ss0 0.65159 0.73261 0.889 0.37379
## f0 2.15013 1.49040 1.443 0.14912
## b0 -2.78565 0.95487 -2.917 0.00353 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 60.571 on 44 degrees of freedom
## Residual deviance: 35.100 on 38 degrees of freedom
## (11 observations deleted due to missingness)
## AIC: 49.1
##
## Number of Fisher Scoring iterations: 6
# Testa o modelo nulo contra o modelo saturado.
mnull <- update(m0, formula = . ~ 1, data = m0$model)
anova(mnull, m0, test = "Chisq")
## Analysis of Deviance Table
##
## Model 1: la48 ~ 1
## Model 2: la48 ~ cor0 + ida0 + ms0 + ss0 + f0 + b0
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 44 60.571
## 2 38 35.100 6 25.471 0.0002792 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Aplica o stepwise para selecionar variáveis.
# Aqui usa-se AIC com k = 3.84.
m1 <- step(update(m0, data = m0$model),
k = qchisq(0.95, df = 1),
trace = 0)
summary(m1)
##
## Call:
## glm(formula = la48 ~ ms0 + b0, family = binomial, data = m0$model)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.7032 -0.7427 -0.3261 0.7290 2.2116
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 13.8716 5.2831 2.626 0.00865 **
## ms0 0.5167 0.1734 2.980 0.00288 **
## b0 -1.6543 0.5307 -3.117 0.00183 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 60.571 on 44 degrees of freedom
## Residual deviance: 42.571 on 42 degrees of freedom
## AIC: 48.571
##
## Number of Fisher Scoring iterations: 5
# Testa o não comprometimento dos termos abandonados.
anova(m0, m1, test = "Chisq")
## Analysis of Deviance Table
##
## Model 1: la48 ~ cor0 + ida0 + ms0 + ss0 + f0 + b0
## Model 2: la48 ~ ms0 + b0
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 38 35.100
## 2 42 42.571 -4 -7.4714 0.113
# Acurácia.
sum(m1$model$la48 == (fitted(m1) > 0.5))/nrow(m1$model)
## [1] 0.7777778
# Diagnóstico.
par(mfrow = c(2, 2))
plot(m1); layout(1)
O procedimento stepwise obteve um modelo com duas variáveis. Não observou-se afastamento dos pressupostos. A acurácia foi 77%.
# Prepara malha para a predição.
# summary(m1$model)
tb_pred <- with(m1$model,
crossing(b0 = seq(min(b0), max(b0), length.out = 24),
ms0 = seq(min(ms0), max(ms0), length.out = 24)))
str(tb_pred)
## tibble [576 × 2] (S3: tbl_df/tbl/data.frame)
## $ b0 : num [1:576] 9.41 9.41 9.41 9.41 9.41 9.41 9.41 9.41 9.41 9.41 ...
## $ ms0: num [1:576] 1.31 2.03 2.76 3.48 4.21 ...
# Predição de cada ponto.
tb_pred$fit <- predict(m1, newdata = tb_pred, type = "response")
cap <- "Latency at 48 h for wounded inoculated fruits predicted as a function of variables measured at inoculation (0 h) and select by stepwise procedure to Chimarrita cultivar."
# Gráfico de contornos de nível.
ggplot(data = tb_pred,
mapping = aes(x = b0, y = ms0, fill = fit)) +
geom_tile() +
geom_contour(mapping = aes(z = fit), color = "black") +
scale_fill_distiller(palette = "Spectral") +
labs(x = "°Brix",
y = "Dry matter",
fill = "Prob.\nlatency")
Latency at 48 h for wounded inoculated fruits predicted as a function of variables measured at inoculation (0 h) and select by stepwise procedure to Chimarrita cultivar.
# Gráfico 3D.
wireframe(fit ~ b0 + ms0,
data = tb_pred,
drape = TRUE, col.regions = my_palette(90),
scales = list(arrows = FALSE),
xlab = list("°Brix", rot = 30),
ylab = list("Dry matter", rot = -40),
zlab = list("Prob. latency", rot = 90))
Latency at 48 h for wounded inoculated fruits predicted as a function of variables measured at inoculation (0 h) and select by stepwise procedure to Chimarrita cultivar.
O gráfico para a probabilidade de esporulação do fruto mostra que há aumento na probabilidade de esporulação com aumento da dry matter e diminuição do brix.
# Seleciona recorte de interesse.
tb_reg <- tb %>%
filter(cultivar == "Maciel", ferimento == "W", lado == "Is") %>%
select(matches("[a-z]0"), la48, la60)
# Conta os valores ausentes.
tb_reg %>%
summarise_all(~sum(is.na(.)))
## # A tibble: 1 × 8
## cor0 ida0 ms0 ss0 f0 b0 la48 la60
## <int> <int> <int> <int> <int> <int> <int> <int>
## 1 0 0 0 0 0 0 0 0
# Análise exploratória.
tb_reg %>%
gather(key = "pred", value = "value", 1:6) %>%
ggplot(mapping = aes(x = value, y = la48)) +
facet_wrap(facets = ~pred, scale = "free_x") +
geom_point() +
geom_smooth(se = FALSE, color = "gray40") +
labs(x = "Variável independente",
y = "Tamanho da lesão")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
# Resumo descritivo.
summary(tb_reg)
## cor0 ida0 ms0 ss0
## Min. : 73.99 Min. :0.330 Min. : 5.75 Min. : 6.87
## 1st Qu.: 94.08 1st Qu.:1.208 1st Qu.:12.37 1st Qu.:10.39
## Median : 99.65 Median :1.630 Median :15.87 Median :11.64
## Mean :102.05 Mean :1.544 Mean :15.15 Mean :11.29
## 3rd Qu.:106.57 3rd Qu.:2.005 3rd Qu.:18.00 3rd Qu.:12.54
## Max. :264.85 Max. :2.150 Max. :20.58 Max. :13.82
## f0 b0 la48 la60
## Min. :2.990 Min. : 9.70 Min. :0.00000 Min. :0.00000
## 1st Qu.:4.543 1st Qu.:10.76 1st Qu.:0.00000 1st Qu.:0.00000
## Median :5.880 Median :11.64 Median :0.00000 Median :0.00000
## Mean :6.057 Mean :11.68 Mean :0.01786 Mean :0.07143
## 3rd Qu.:7.700 3rd Qu.:12.49 3rd Qu.:0.00000 3rd Qu.:0.00000
## Max. :9.310 Max. :13.88 Max. :1.00000 Max. :1.00000
# Frequências da resposta.
tb_reg %>%
count(la48, la60)
## # A tibble: 3 × 3
## la48 la60 n
## <dbl> <dbl> <int>
## 1 0 0 52
## 2 0 1 3
## 3 1 1 1
Não foi possível obter modelo para a latência para a cultivar Maciel pois houve um grande e impeditivo desequilíbrio de classe na variável desfecho. Isso porque com 48 e 60 horas observou-se apenas alguns frutos com esporulação. Talvez se o período de observação fosse prolongado, poderia-se ter mais frutos esporulados para permitir ajustar o modelo. Nos próximos experimentos pode-se usar o critério de encerrar o experimento apenas quando 50% dos frutos apresentar esporulação.