library(caret)
## Carregando pacotes exigidos: ggplot2
## Carregando pacotes exigidos: lattice
getwd()
## [1] "C:/Users/LAFIECO/Downloads"
setwd("C:/Users/LAFIECO/Downloads")

df <- read.csv("DadosModeloMultivariadoSoja.csv", sep=";")

df$Trataments <- as.factor(df$Trataments)

# drop coluna
df <- subset(df, select = -Tratament_numeric)

# Criar variáveis dummy usando dummyVars
dummy_var <- dummyVars(~ Trataments, data = df)

# Transformar os dados originais usando predict
df_dummies <- predict(dummy_var, newdata = df)

# Adicionar as dummies ao conjunto de dados original
df_dummies <- cbind(df, df_dummies)

Deixando váriaveis dummies

Modelo Gamma com link Log

modelo_gammainverse <- glm(Grain ~ TotalBiomass:Trataments, data = df_dummies, family='Gamma'(link='inverse'))  
summary(modelo_gammainverse)
## 
## Call:
## glm(formula = Grain ~ TotalBiomass:Trataments, family = Gamma(link = "inverse"), 
##     data = df_dummies)
## 
## Coefficients:
##                                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                         0.1221653  0.0550900   2.218   0.0309 *  
## TotalBiomass:TratamentsAmb          0.0002236  0.0062497   0.036   0.9716    
## TotalBiomass:TratamentsAmbDrought   0.0254435  0.0110430   2.304   0.0252 *  
## TotalBiomass:TratamentsAmbTemp      0.2532254  0.0567660   4.461 4.28e-05 ***
## TotalBiomass:TratamentsElev        -0.0030452  0.0027900  -1.092   0.2800    
## TotalBiomass:TratamentsElevDrought  0.0115957  0.0067860   1.709   0.0933 .  
## TotalBiomass:TratamentsElevTemp    -0.0030303  0.0029544  -1.026   0.3097    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Gamma family taken to be 0.4453516)
## 
##     Null deviance: 174.08  on 59  degrees of freedom
## Residual deviance: 112.31  on 53  degrees of freedom
## AIC: 313
## 
## Number of Fisher Scoring iterations: 7
plot(modelo_gammainverse)

Modelo gamma link inverse

# Explorando um pouco as possibilidades para modelo com resposta binária
pontodecorte = 2 
df_dummies$Grain_not0 = 0
df_dummies$Grain_not0[ which(df$Grain > pontodecorte) ] = 1 
modelo_binomial <- glm(Grain_not0 ~ TotalBiomass:Trataments, data = df_dummies, family='binomial'(link='logit'))  # coloca -1 para o intercepto ser zero e ficar a mesma baseline para todos os tratamentos
## Warning: glm.fit: probabilidades ajustadas numericamente 0 ou 1 ocorreu
summary(modelo_binomial)
## 
## Call:
## glm(formula = Grain_not0 ~ TotalBiomass:Trataments, family = binomial(link = "logit"), 
##     data = df_dummies)
## 
## Coefficients:
##                                     Estimate Std. Error z value Pr(>|z|)
## (Intercept)                           0.1117     2.6917   0.042    0.967
## TotalBiomass:TratamentsAmb            2.9583  1050.3721   0.003    0.998
## TotalBiomass:TratamentsAmbDrought     0.1592     0.3502   0.455    0.649
## TotalBiomass:TratamentsAmbTemp       -2.8349  1117.1943  -0.003    0.998
## TotalBiomass:TratamentsElev           1.2829   503.5184   0.003    0.998
## TotalBiomass:TratamentsElevDrought    0.1164     0.2452   0.475    0.635
## TotalBiomass:TratamentsElevTemp       1.5319   556.8554   0.003    0.998
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 65.193  on 59  degrees of freedom
## Residual deviance: 19.761  on 53  degrees of freedom
## AIC: 33.761
## 
## Number of Fisher Scoring iterations: 20
plot(modelo_binomial)  # olhando os residuos do modelo

## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produzidos
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produzidos

Modelo binomial