library(wooldridge)
data(bwght, package = 'wooldridge')
library(rmarkdown)
paged_table(bwght)
lm(bwght ~ cigs + faminc, data = bwght)
## 
## Call:
## lm(formula = bwght ~ cigs + faminc, data = bwght)
## 
## Coefficients:
## (Intercept)         cigs       faminc  
##   116.97413     -0.46341      0.09276
lm(bwght$bwght ~ bwght$cigs + bwght$faminc)
## 
## Call:
## lm(formula = bwght$bwght ~ bwght$cigs + bwght$faminc)
## 
## Coefficients:
##  (Intercept)    bwght$cigs  bwght$faminc  
##    116.97413      -0.46341       0.09276
bwght$bwghtlbs <- bwght$bwght / 16
lm(bwght$bwghtlbs ~ bwght$cigs + bwght$faminc)
## 
## Call:
## lm(formula = bwght$bwghtlbs ~ bwght$cigs + bwght$faminc)
## 
## Coefficients:
##  (Intercept)    bwght$cigs  bwght$faminc  
##     7.310883     -0.028963      0.005798
lm(I(bwght/16) ~ cigs + faminc, data = bwght)
## 
## Call:
## lm(formula = I(bwght/16) ~ cigs + faminc, data = bwght)
## 
## Coefficients:
## (Intercept)         cigs       faminc  
##    7.310883    -0.028963     0.005798
lm(bwght ~ I(cigs/20) + faminc, data = bwght)
## 
## Call:
## lm(formula = bwght ~ I(cigs/20) + faminc, data = bwght)
## 
## Coefficients:
## (Intercept)   I(cigs/20)       faminc  
##   116.97413     -9.26815      0.09276
model_1<- lm(bwght ~ cigs + faminc, data = bwght)
model_2<- lm(I(bwght/16) ~ cigs + faminc, data = bwght)
model_3<- lm(bwght ~ I(cigs/20) + faminc, data = bwght)
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
stargazer(list(model_1,model_2,model_3), type = "text")
## 
## =================================================================
##                                        Dependent variable:       
##                                 ---------------------------------
##                                   bwght    I(bwght/16)   bwght   
##                                    (1)         (2)        (3)    
## -----------------------------------------------------------------
## cigs                            -0.463***   -0.029***            
##                                  (0.092)     (0.006)             
##                                                                  
## I(cigs/20)                                             -9.268*** 
##                                                         (1.832)  
##                                                                  
## faminc                           0.093***   0.006***    0.093*** 
##                                  (0.029)     (0.002)    (0.029)  
##                                                                  
## Constant                        116.974***  7.311***   116.974***
##                                  (1.049)     (0.066)    (1.049)  
##                                                                  
## -----------------------------------------------------------------
## Observations                      1,388       1,388      1,388   
## R2                                0.030       0.030      0.030   
## Adjusted R2                       0.028       0.028      0.028   
## Residual Std. Error (df = 1385)   20.063      1.254      20.063  
## F Statistic (df = 2; 1385)      21.274***   21.274***  21.274*** 
## =================================================================
## Note:                                 *p<0.1; **p<0.05; ***p<0.01
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
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
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)

summary(ornek6_2_poly)
## 
## Call:
## lm(formula = log(price) ~ log(nox) + log(dist) + poly(rooms, 
##     2, raw = TRUE) + 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 *  
## poly(rooms, 2, raw = TRUE)1 -0.545113   0.165454  -3.295  0.00106 ** 
## poly(rooms, 2, raw = TRUE)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
library(car)
## Zorunlu paket yükleniyor: carData
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
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