Kirliliğin konut fiyatları üzerindeki etkileri

library(wooldridge)
data(hprice2)
library(rmarkdown)
paged_table(hprice2)
lm(scale(price) ~ 0 + scale(nox) + scale(crime) + scale(rooms) + scale(dist) + scale(stratio), data = hprice2)
## 
## Call:
## lm(formula = scale(price) ~ 0 + scale(nox) + scale(crime) + scale(rooms) + 
##     scale(dist) + scale(stratio), data = hprice2)
## 
## Coefficients:
##     scale(nox)    scale(crime)    scale(rooms)     scale(dist)  scale(stratio)  
##        -0.3404         -0.1433          0.5139         -0.2348         -0.2703

Logaritmik fonksiyonel form

lm(log(price) ~ log(nox) +  rooms , data = hprice2)
## 
## Call:
## lm(formula = log(price) ~ log(nox) + rooms, data = hprice2)
## 
## Coefficients:
## (Intercept)     log(nox)        rooms  
##      9.2337      -0.7177       0.3059

Karasel modeller

ornek6_2<-lm(log(price) ~ log(nox) + log(dist)+  rooms + I(rooms^2) + stratio , data = hprice2)
summary(ornek6_2)
## 
## Call:
## lm(formula = log(price) ~ log(nox) + log(dist) + rooms + I(rooms^2) + 
##     stratio, data = hprice2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.04285 -0.12774  0.02038  0.12650  1.25272 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 13.385477   0.566473  23.630  < 2e-16 ***
## log(nox)    -0.901682   0.114687  -7.862 2.34e-14 ***
## log(dist)   -0.086781   0.043281  -2.005  0.04549 *  
## rooms       -0.545113   0.165454  -3.295  0.00106 ** 
## I(rooms^2)   0.062261   0.012805   4.862 1.56e-06 ***
## stratio     -0.047590   0.005854  -8.129 3.42e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2592 on 500 degrees of freedom
## Multiple R-squared:  0.6028, Adjusted R-squared:  0.5988 
## F-statistic: 151.8 on 5 and 500 DF,  p-value: < 2.2e-16
ornek6_2_poly<-lm(log(price) ~ log(nox) + log(dist)+  poly(rooms, 2, raw = TRUE ) + stratio , data = hprice2)
library(car)
## Warning: package 'car' was built under R version 4.2.2
## Zorunlu paket yükleniyor: carData
## Warning: package 'carData' was built under R version 4.2.2
Anova(ornek6_2_poly)
## Anova Table (Type II tests)
## 
## Response: log(price)
##                            Sum Sq  Df  F value    Pr(>F)    
## log(nox)                    4.153   1  61.8129 2.341e-14 ***
## log(dist)                   0.270   1   4.0204   0.04549 *  
## poly(rooms, 2, raw = TRUE) 14.838   2 110.4188 < 2.2e-16 ***
## stratio                     4.440   1  66.0848 3.423e-15 ***
## Residuals                  33.595 500                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Etkileşim terimli modeller

data("attend")
(ornek6_3 <- lm(stndfnl~ atndrte*priGPA + ACT + I(priGPA^2) + I(ACT^2), data=attend))
## 
## Call:
## lm(formula = stndfnl ~ atndrte * priGPA + ACT + I(priGPA^2) + 
##     I(ACT^2), data = attend)
## 
## Coefficients:
##    (Intercept)         atndrte          priGPA             ACT     I(priGPA^2)  
##       2.050293       -0.006713       -1.628540       -0.128039        0.295905  
##       I(ACT^2)  atndrte:priGPA  
##       0.004533        0.005586
max(attend$priGPA)
## [1] 3.93
min(attend$priGPA)
## [1] 0.857
mean(attend$priGPA)
## [1] 2.586775
katsayi <- coef(ornek6_3)
katsayi["atndrte"]
##      atndrte 
## -0.006712928
katsayi["atndrte:priGPA"]
## atndrte:priGPA 
##    0.005585907
katsayi["atndrte"] + mean(attend$priGPA)*katsayi["atndrte:priGPA"]
##     atndrte 
## 0.007736558
library(car)
linearHypothesis(ornek6_3, c("atndrte + 2.59*atndrte:priGPA"))
## Linear hypothesis test
## 
## Hypothesis:
## atndrte  + 2.59 atndrte:priGPA = 0
## 
## Model 1: restricted model
## Model 2: stndfnl ~ atndrte * priGPA + ACT + I(priGPA^2) + I(ACT^2)
## 
##   Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
## 1    674 519.34                                
## 2    673 512.76  1    6.5772 8.6326 0.003415 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
data(gpa2)
ornek6_5 <- lm(colgpa~sat+ hsperc + hsize + I(hsize^2), data=gpa2 )
summary(ornek6_5)
## 
## Call:
## lm(formula = colgpa ~ sat + hsperc + hsize + I(hsize^2), data = gpa2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.57543 -0.35081  0.03342  0.39945  1.81683 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.493e+00  7.534e-02  19.812  < 2e-16 ***
## sat          1.492e-03  6.521e-05  22.886  < 2e-16 ***
## hsperc      -1.386e-02  5.610e-04 -24.698  < 2e-16 ***
## hsize       -6.088e-02  1.650e-02  -3.690 0.000228 ***
## I(hsize^2)   5.460e-03  2.270e-03   2.406 0.016191 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5599 on 4132 degrees of freedom
## Multiple R-squared:  0.2781, Adjusted R-squared:  0.2774 
## F-statistic:   398 on 4 and 4132 DF,  p-value: < 2.2e-16
tahmin_verileri = data.frame(sat=1200, hsperc=30, hsize=5)
tahmin_verileri
##    sat hsperc hsize
## 1 1200     30     5
tahmin_verileri = data.frame(sat=1200, hsperc=30, hsize=5)
tahmin_verileri
##    sat hsperc hsize
## 1 1200     30     5
predict(ornek6_5, tahmin_verileri, interval = "confidence" )
##        fit      lwr      upr
## 1 2.700075 2.661104 2.739047