dat <- data.frame(x1 = c(3, 2, 4, 9, 5, 3, 6, 4, 5, 6, 3, 5),
x2 = c(1, 4, 3, 1, 2, 4, 3, 5, 1, 7, 8, 7),
x3 = c(0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1),
y1 = c(2, 7, 4, 4, 7, 8, 4, 2, 5, 1, 3, 8),
y2 = c(0, 1, 0, 2, 0, 1, 0, 0, 1, 2, 1, 0))
#-------------------------------------------------------------------------------
# Example 1: Linear model
mod1 <- lm(y1 ~ x1 + x2 + x3, data = dat)
robust.coef(mod1)
#-------------------------------------------------------------------------------
# Example 2: Generalized linear model
mod2 <- glm(y2 ~ x1 + x2 + x3, data = dat, family = poisson())
robust.coef(mod2)
if (FALSE) {
#----------------------------------------------------------------------------
# Write Results
# Example 3a: Write Results into a text file
robust.coef(mod1, write = "Robust_Coef.txt", output = FALSE)
# Example 3b: Write Results into an Excel file
robust.coef(mod1, write = "Robust_Coef.xlsx", output = FALSE)
result <- robust.coef(mod1, output = FALSE)
write.result(result, "Robust_Coef.xlsx")
}
Run the code above in your browser using DataLab