A modelagem a seguir foi proposta por Yen et. al (1999), nele, desejamos ajustar os parâmetros fuzzy para o seguinte modelo:
\[\pmb{\widetilde{Y}} = f(\pmb{x}, \pmb{\widetilde{A}}) = \widetilde{A}_0 + \widetilde{A}_1x_1 + \dots + \widetilde{A}_nx_n\]
Para a formulação do problema Ver Yen et. al. (1999).
Incialmente, tomemos o exemplo de Yen, ajustando para o seguinte conjunto de dados:
y = c(3.54, 4.05, 4.51, 2.63, 1.9)
x0 = rep(1,5)
x1 = c(0.84, 0.65, 0.76, 0.7, 0.43)
x2 = c(0.86, 0.52, 0.57, 0.3, 0.6)
X = cbind(x0,x1,x2)
data = data.frame(y,x1,x2)
data
## y x1 x2
## 1 3.54 0.84 0.86
## 2 4.05 0.65 0.52
## 3 4.51 0.76 0.57
## 4 2.63 0.70 0.30
## 5 1.90 0.43 0.60
plot(data)
Ajustando através do modelo linear normal:
#Comparando brevemente com a regressão clássica
mod = lm(y ~ x1 + x2)
summary(mod)
##
## Call:
## lm(formula = y ~ x1 + x2)
##
## Residuals:
## 1 2 3 4 5
## -0.5669 0.8480 0.7906 -0.7965 -0.2753
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.1350 2.5975 0.052 0.963
## x1 4.6832 3.6722 1.275 0.330
## x2 0.0442 2.8368 0.016 0.989
##
## Residual standard error: 1.09 on 2 degrees of freedom
## Multiple R-squared: 0.4709, Adjusted R-squared: -0.05823
## F-statistic: 0.8899 on 2 and 2 DF, p-value: 0.5291
library(hnp)
## Loading required package: MASS
hnp(mod$residuals)
## Half-normal plot with simulated envelope generated assuming the residuals are
## normally distributed under the null hypothesis.
Agora, ajustando o modelo de regressão fuzzy através da formulação matemática de Yen para o caso simétrico:
library(lpSolve)
f.obj <- c(1, 3.38, 2.85, 0, 0, 0)
f.con <- matrix(c(0.5, 0.42, 0.43, 1, 0.84, 0.86,
0.5, 0.42, 0.23, -1, -0.84, -0.86,
0.5, 0.325, 0.26, 1, 0.65, 0.52,
0.5, 0.325, 0.26, -1, -0.65, -0.52,
0.5, 0.38, 0.285, 1, 0.76, 0.57,
0.5, 0.38, 0.285, -1, 0.76, -0.57,
0.5, 0.35, 0.15, 1, 0.7, 0.3,
0.5, 0.35, 0.15, -1, -0.7, -0.3,
0.5, 0.215, 0.3, 1, 0.43, 0.6,
0.5, 0.215, 0.3, -1, -0.43, -0.6),
nrow=10, ncol=6, byrow=TRUE)
f.dir <- c(">=",">=",">=",">=",">=",">=",">=",">=",">=",">=")
f.rhs <- c(3.54, -3.54, 4.05, -4.05, 4.51,
-4.51, 2.63, -2.63, 1.9, -1.9)
lp.sol = lp("min", f.obj, f.con, f.dir, f.rhs)
lp.sol$solution
## [1] 1.4677174 0.0000000 0.0000000 0.6707428 3.5289855 0.7427536
Agora o modelo para o caso asimétrico: Adicionando um vetor de parâmetros de assimetria, baseado na informação a priori que temos: \(s_i^R = k_i*S_i^L\). Assumimos \(k_0 = 1.4; k_1 = 1.6; k_2 = 1.9\).
f.con <- matrix(c(0.5, 0.42, 0.43, 1, 0.84, 0.86,
0.7, 0.672, 0.817, -1, -0.84, -0.86,
0.5, 0.325, 0.26, 1, 0.65, 0.52,
0.7, 0.52, 0.494, -1, -0.65, -0.52,
0.5, 0.38, 0.285, 1, 0.76, 0.57,
0.7, 0.60, 0.542, -1, -0.76, -0.57,
0.5, 0.35, 0.15, 1, 0.7, 0.3,
0.7, 0.56, 0.285, -1, -0.7, -0.3,
0.5, 0.215, 0.3, 1, 0.43, 0.6,
0.7, 0.344, 0.57, -1, -0.43, -0.6),
nrow=10, ncol=6, byrow=TRUE)
f.dir <- c(">=",">=",">=",">=",">=",">=",">=",">=",">=",">=")
f.rhs <- c(3.54, -3.54, 4.05, -4.05, 4.51,
-4.51, 2.63, -2.63, 1.9, -1.9)
lp.sol2 = lp("min", f.obj, f.con, f.dir, f.rhs)
lp.sol2$solution
## [1] 1.2230978 0.0000000 0.0000000 0.7930525 3.5289855 0.7427536
Agora vamos gerar o ajuste para o exemplo de precificação de casas. Para o modelo de regressão linear fuzzy de tanaka.
y = c(6060, 7100, 8080, 8260, 8650, 8520, 9170, 10310,
10920, 12030, 13940, 14200, 16010, 16320, 16990)
e = c(550, 50, 400, 150, 750, 450, 700, 200, 600, 100,
350, 250, 300, 500, 650)
x0 = rep(1, 15)
x1 = c(rep(1,5), rep(2,5), rep(3,5))
x2 = c(32.09, 62.10, 63.76, 74.52, 75.38, 52.99, 62.93, 72.04,
76.12, 90.26, 85.70, 95.27, 105.98, 79.25, 120.50)
x3 = c(36.43, 26.50, 44.71, 38.09, 41.40, 26.49, 26.49, 33.12,
43.06, 42.64, 31.33, 27.64, 27.64, 66.81, 32.25)
x4 = c(5, 6, 7, 8, 7, 4, 5, 6, 7, 7, 6, 6, 6, 6, 6)
x5 = x1 = c(rep(1,5), rep(2,5), rep(3,5))
Y = cbind(y, e)
X = cbind(x0, x1, x2, x3, x4, x5)
data = data.frame(y, e, x0, x1, x2, x3, x4, x5)
data
## y e x0 x1 x2 x3 x4 x5
## 1 6060 550 1 1 32.09 36.43 5 1
## 2 7100 50 1 1 62.10 26.50 6 1
## 3 8080 400 1 1 63.76 44.71 7 1
## 4 8260 150 1 1 74.52 38.09 8 1
## 5 8650 750 1 1 75.38 41.40 7 1
## 6 8520 450 1 2 52.99 26.49 4 2
## 7 9170 700 1 2 62.93 26.49 5 2
## 8 10310 200 1 2 72.04 33.12 6 2
## 9 10920 600 1 2 76.12 43.06 7 2
## 10 12030 100 1 2 90.26 42.64 7 2
## 11 13940 350 1 3 85.70 31.33 6 3
## 12 14200 250 1 3 95.27 27.64 6 3
## 13 16010 300 1 3 105.98 27.64 6 3
## 14 16320 500 1 3 79.25 66.81 6 3
## 15 16990 650 1 3 120.50 32.25 6 3
# Utilizando o pacote: fuzzyreg para ajustar o modelo
# Através do método de tanaka (possibilistic linear regression):
library(fuzzyreg)
## Loading required package: limSolve
## Loading required package: quadprog
f.model = tanaka(X,Y, h = 0.5)
f.model
##
## Fuzzy linear model using the PLR method
##
## Call:
## NULL
##
## Coefficients in form of symmetric triangular fuzzy numbers:
##
## center left.spread right.spread
## x0 -628.41199 1611.796 1611.796
## x1 2143.53624 0.000 0.000
## x2 89.58089 0.000 0.000
## x3 81.43006 0.000 0.000
## x4 -365.43402 0.000 0.000
## x5 0.00000 0.000 0.000
f.model$fuzzynum
## [1] "symmetric triangular"
f.model$method
## [1] "PLR"
#utilizando a função mais "geral" para o mesmo modelo
#Possibilistic linear regression analysis for fuzzy data
f.model2 = fuzzylm(Y ~ x0 + x1 + x2 + x3 + x4 + x5, data = data, method = "plr")
f.model2
##
## Fuzzy linear model using the PLR method
##
## Call:
## fuzzylm(formula = Y ~ x0 + x1 + x2 + x3 + x4 + x5, data = data,
## method = "plr")
##
## Coefficients in form of symmetric triangular fuzzy numbers:
##
## center left.spread right.spread
## (Intercept) -688.01235 1066.173 1066.173
## x0 0.00000 0.000 0.000
## x1 2186.78588 0.000 0.000
## x2 90.78358 0.000 0.000
## x3 100.02065 0.000 0.000
## x4 -502.38875 0.000 0.000
## x5 0.00000 0.000 0.000
# plrls Fuzzy approximations with non-symmetric fuzzy
# parameters in fuzzy regression analysis.
# (Lee and Tanaka, 1999)
#f.model3 = fuzzylm(y ~ x0 + x1 + x2 + x3 + x4 + x5, data = data, method = "plrls")
#f.model3 # Ver o artigo original
# Fuzzy linear regression analysis: a multi-objective
#programming approach. moflr (Nasrabadi et. al., 2005)
#f.model4 = fuzzylm(y ~ x0 + x1 + x2 + x3 + x4 + x5, data = data, method = "plrls")
#f.model4