a

library(MASS)
names(Boston)
##  [1] "crim"    "zn"      "indus"   "chas"    "nox"     "rm"      "age"    
##  [8] "dis"     "rad"     "tax"     "ptratio" "black"   "lstat"   "medv"
x <- Boston[-1]

lapply(x, function(x) { m<-lm(Boston$crim ~ x)
                        summary(m)$coefficients})
## $zn
##                         Estimate           Std. Error             t value
## (Intercept)  4.45369375508637777 0.417217777789882172 10.6747458813448066
## x           -0.07393497740412304 0.016094596193225372 -4.5937764773026215
##                           Pr(>|t|)
## (Intercept) 4.0376680504893932e-24
## x           5.5064721076796426e-06
## 
## $indus
##                         Estimate          Std. Error             t value
## (Intercept) -2.06374260632779771 0.66722829790554561 -3.0930082144386897
## x            0.50977633110422849 0.05102433233173044  9.9908476565643269
##                           Pr(>|t|)
## (Intercept) 2.0912655160398148e-03
## x           1.4503489330275649e-21
## 
## $chas
##                        Estimate          Std. Error             t value
## (Intercept)  3.7444468365180472 0.39611112235384283  9.4530211983625225
## x           -1.8927765508037846 1.50611548365537207 -1.2567273700752206
##                           Pr(>|t|)
## (Intercept) 1.2395054847495135e-19
## x           2.0943450153519738e-01
## 
## $nox
##                        Estimate         Std. Error             t value
## (Intercept) -13.719882309974343 1.6994792810318609 -8.0729918058454579
## x            31.248531201122912 2.9991903806117346 10.4189888721733155
##                           Pr(>|t|)
## (Intercept) 5.0768144262210831e-15
## x           3.7517392603568967e-23
## 
## $rm
##                        Estimate          Std. Error             t value
## (Intercept) 20.4818041777924442 3.36447421072379926  6.0876686504267168
## x           -2.6840512241139534 0.53204108337701461 -5.0448194847614483
##                           Pr(>|t|)
## (Intercept) 2.2719998289032299e-09
## x           6.3467029846874938e-07
## 
## $age
##                         Estimate           Std. Error             t value
## (Intercept) -3.77790631796825815 0.943984715434622257 -4.0020842034808402
## x            0.10778622713953308 0.012736436258791776  8.4628246826210756
##                           Pr(>|t|)
## (Intercept) 7.2217177822382622e-05
## x           2.8548693502440932e-16
## 
## $dis
##                        Estimate          Std. Error             t value
## (Intercept)  9.4992616465572777 0.73039719937929293 13.0056107206187974
## x           -1.5509016824101005 0.16833003092970372 -9.2134580730741522
##                           Pr(>|t|)
## (Intercept) 1.5027478501916754e-33
## x           8.5199487669260976e-19
## 
## $rad
##                         Estimate          Std. Error             t value
## (Intercept) -2.28715944831037588 0.44347583375963573 -5.1573485502482157
## x            0.61791092732720132 0.03433181966784242 17.9981991431109556
##                           Pr(>|t|)
## (Intercept) 3.6058461635571157e-07
## x           2.6938443981863264e-56
## 
## $tax
##                          Estimate            Std. Error
## (Intercept) -8.528369093069132489 0.8158093916455729788
## x            0.029742252822765342 0.0018474151191032497
##                         t value               Pr(>|t|)
## (Intercept) -10.453874618759315 2.7736004880973909e-23
## x            16.099388012588353 2.3571268352568462e-47
## 
## $ptratio
##                         Estimate          Std. Error             t value
## (Intercept) -17.6469334724482039 3.14727179816026181 -5.6070573513109743
## x             1.1519827870705928 0.16937360925271472  6.8014302355201703
##                           Pr(>|t|)
## (Intercept) 3.3952549147926249e-08
## x           2.9429224473596709e-11
## 
## $black
##                          Estimate           Std. Error             t value
## (Intercept) 16.553529224206666726 1.425902754886328561 11.6091571935607174
## x           -0.036279640567330754 0.003873153831701546 -9.3669505895644889
##                           Pr(>|t|)
## (Intercept) 8.9222392516090651e-28
## x           2.4872739737737511e-19
## 
## $lstat
##                         Estimate          Std. Error             t value
## (Intercept) -3.33053805714505158 0.69375829403953915 -4.8007181834935082
## x            0.54880478206239813 0.04776097094418140 11.4906537956230075
##                           Pr(>|t|)
## (Intercept) 2.0870217738175767e-06
## x           2.6542772314732674e-27
## 
## $medv
##                         Estimate           Std. Error             t value
## (Intercept) 11.79653575022189749 0.934189161731609152 12.6275664859522543
## x           -0.36315992225760252 0.038390174674223523 -9.4597100778872072
##                           Pr(>|t|)
## (Intercept) 5.9341188686781161e-32
## x           1.1739870821944873e-19
for(i in seq(dim(x)[2])){
  m <- lm(Boston$crim ~ x[[i]])
  if(summary(m)$coefficients[2,4] < 0.05){
    plot(x[[i]],Boston$crim,xlab = names(x)[i])
  }
}

b

m<-lm(crim~.,data = Boston)
summary(m)
## 
## Call:
## lm(formula = crim ~ ., data = Boston)
## 
## Residuals:
##              Min               1Q           Median               3Q 
## -9.9237390943432 -2.1197715348446 -0.3533348302087  1.0187970696539 
##              Max 
## 75.0511785694575 
## 
## Coefficients:
##                         Estimate           Std. Error  t value   Pr(>|t|)
## (Intercept)  17.0332275226344976   7.2349030308290310  2.35431  0.0189491
## zn            0.0448552146700317   0.0187340706387292  2.39431  0.0170249
## indus        -0.0638548235877007   0.0834072406727293 -0.76558  0.4442940
## chas         -0.7491336105105995   1.1801467723714198 -0.63478  0.5258670
## nox         -10.3135349120666842   5.2755363149054073 -1.95497  0.0511520
## rm            0.4301305058640464   0.6128303094666474  0.70188  0.4830888
## age           0.0014516434361821   0.0179251276827142  0.08098  0.9354878
## dis          -0.9871757255028882   0.2818172657905536 -3.50289  0.0005022
## rad           0.5882085914734919   0.0880492738506307  6.68045 6.4605e-11
## tax          -0.0037800163848591   0.0051555868418552 -0.73319  0.4637927
## ptratio      -0.2710805584722512   0.1864504941616461 -1.45390  0.1466113
## black        -0.0075375048884921   0.0036733215239152 -2.05196  0.0407023
## lstat         0.1262113764594996   0.0757248372790315  1.66671  0.0962084
## medv         -0.1988868212656190   0.0605159897520774 -3.28652  0.0010868
##                
## (Intercept) *  
## zn          *  
## indus          
## chas           
## nox         .  
## rm             
## age            
## dis         ***
## rad         ***
## tax            
## ptratio        
## black       *  
## lstat       .  
## medv        ** 
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 6.4391982739401996 on 492 degrees of freedom
## Multiple R-squared:  0.45401038980421,   Adjusted R-squared:  0.43958383506327 
## F-statistic: 31.470465260541 on 13 and 492 DF,  p-value: < 2.22044604925e-16

c

uni.coe<-sapply(x, function(x) { m<-lm(Boston$crim ~ x)
                        m$coefficients[2]})
m<-lm(crim~.,data = Boston)
plot(uni.coe,m$coefficients[-1],ylab = 'full.coe')

d

lapply(x, function(x) { m<-lm(Boston$crim ~ x + I(x^2) + I(x^3))
                        summary(m)})
## $zn
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##              Min               1Q           Median               3Q 
## -4.8210700762792 -4.6140025762792 -1.2942050762792  0.4731790778097 
##              Max 
## 84.1301499237209 
## 
## Coefficients:
##                         Estimate           Std. Error  t value   Pr(>|t|)
## (Intercept)  4.8460500762791e+00  4.3298463654730e-01 11.19220 < 2.22e-16
## x           -3.3218841472213e-01  1.0980813950251e-01 -3.02517  0.0026123
## I(x^2)       6.4826336527385e-03  3.8607278646367e-03  1.67912  0.0937505
## I(x^3)      -3.7757925278318e-05  3.1386150894709e-05 -1.20301  0.2295386
##                
## (Intercept) ***
## x           ** 
## I(x^2)      .  
## I(x^3)         
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 8.3722071728541003 on 502 degrees of freedom
## Multiple R-squared:  0.058241974222583,  Adjusted R-squared:  0.052613938211961 
## F-statistic: 10.348543277381 on 3 and 502 DF,  p-value: 1.28129325849e-06
## 
## 
## $indus
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##              Min               1Q           Median               3Q 
## -8.2784560767506 -2.5135676346500  0.0535570375577  0.7639784915506 
##              Max 
## 79.7127315155538 
## 
## Coefficients:
##                         Estimate           Std. Error  t value   Pr(>|t|)
## (Intercept)  3.66256827868588397  1.57398333248029099  2.32694   0.020365
## x           -1.96521293430683874  0.48199005778718990 -4.07729 5.2971e-05
## I(x^2)       0.25193729792732944  0.03932212447290314  6.40701 3.4202e-10
## I(x^3)      -0.00697600854021407  0.00095665955969848 -7.29205 1.1964e-12
##                
## (Intercept) *  
## x           ***
## I(x^2)      ***
## I(x^3)      ***
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 7.4231209547035002 on 502 degrees of freedom
## Multiple R-squared:  0.25965785791957,   Adjusted R-squared:  0.25523350248881 
## F-statistic: 58.688290754025 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $chas
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##              Min               1Q           Median               3Q 
## -3.7381268365181 -3.6607043365180 -3.4350468365180  0.0184248011829 
##              Max 
## 85.2317531634820 
## 
## Coefficients: (2 not defined because of singularities)
##                      Estimate        Std. Error  t value Pr(>|t|)    
## (Intercept)  3.74444683651805  0.39611112235384  9.45302  < 2e-16 ***
## x           -1.89277655080378  1.50611548365537 -1.25673  0.20943    
## I(x^2)                     NA                NA       NA       NA    
## I(x^3)                     NA                NA       NA       NA    
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 8.5966152647359007 on 504 degrees of freedom
## Multiple R-squared:  0.0031238689633056, Adjusted R-squared:  0.0011459401318836 
## F-statistic: 1.5793636826962 on 1 and 504 DF,  p-value: 0.2094345015352
## 
## 
## $nox
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##              Min               1Q           Median               3Q 
## -9.1099512146499 -2.0678263279106 -0.2547383146506  0.7387433349973 
##              Max 
## 78.3024230170744 
## 
## Coefficients:
##                       Estimate         Std. Error  t value   Pr(>|t|)    
## (Intercept)   233.086590663052    33.643101169498  6.92821 1.3119e-11 ***
## x           -1279.371251662180   170.397473255529 -7.50816 2.7584e-13 ***
## I(x^2)       2248.544052564005   279.899272947518  8.03340 6.8113e-15 ***
## I(x^3)      -1245.702873746836   149.281639892936 -8.34465 6.9611e-16 ***
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 7.2336050301916996 on 502 degrees of freedom
## Multiple R-squared:  0.29697789562874,   Adjusted R-squared:  0.29277656831178 
## F-statistic: 70.686683808212 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $rm
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##               Min                1Q            Median                3Q 
## -18.4850427719025  -3.4675212148648  -2.2212421602579  -0.0148709586322 
##               Max 
##  87.2185956762054 
## 
## Coefficients:
##                       Estimate         Std. Error  t value Pr(>|t|)  
## (Intercept) 112.62459631864809  64.51723593751805  1.74565 0.081483 .
## x           -39.15013633707651  31.31149150152691 -1.25034 0.211756  
## I(x^2)        4.55089591485317   5.00986166730385  0.90839 0.364109  
## I(x^3)       -0.17447695018089   0.26374704610868 -0.66153 0.508575  
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 8.329675785029 on 502 degrees of freedom
## Multiple R-squared:  0.067786061168787,  Adjusted R-squared:  0.062215061534337 
## F-statistic: 12.167665700356 on 3 and 502 DF,  p-value: 1.0673927032238e-07
## 
## 
## $age
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##              Min               1Q           Median               3Q 
## -9.7624242923309 -2.6728191652813 -0.5163346187213  0.0189634733803 
##              Max 
## 82.8422952372915 
## 
## Coefficients:
##                         Estimate           Std. Error  t value  Pr(>|t|)
## (Intercept) -2.5487634036758e+00  2.7691404743808e+00 -0.92042 0.3577971
## x            2.7365313056117e-01  1.8637963541052e-01  1.46826 0.1426608
## I(x^2)      -7.2295955756739e-03  3.6369953305316e-03 -1.98779 0.0473773
## I(x^3)       5.7453070396629e-05  2.1093552298322e-05  2.72373 0.0066799
##               
## (Intercept)   
## x             
## I(x^2)      * 
## I(x^3)      **
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 7.8397026505126002 on 502 degrees of freedom
## Multiple R-squared:  0.17423099358657,   Adjusted R-squared:  0.16929611904625 
## F-statistic: 35.306063439518 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $dis
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##               Min                1Q            Median                3Q 
## -10.7567245560297  -2.5881570432624   0.0309925523167   1.2665308812104 
##               Max 
##  76.3783926329046 
## 
## Coefficients:
##                        Estimate          Std. Error  t value   Pr(>|t|)
## (Intercept)  30.047611563456542   2.445869712784547 12.28504 < 2.22e-16
## x           -15.554353488051415   1.735967449587628 -8.96005 < 2.22e-16
## I(x^2)        2.452072169574368   0.346419441147264  7.07833 4.9412e-12
## I(x^3)       -0.118598636902677   0.020400401592936 -5.81354 1.0888e-08
##                
## (Intercept) ***
## x           ***
## I(x^2)      ***
## I(x^3)      ***
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 7.331478998213 on 502 degrees of freedom
## Multiple R-squared:  0.27782477308674,   Adjusted R-squared:  0.27350898487809 
## F-statistic: 64.374051657638 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $rad
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##               Min                1Q            Median                3Q 
## -10.3805547092502  -0.4117729243100  -0.2690159062635   0.1788220744300 
##               Max 
##  76.2170752907498 
## 
## Coefficients:
##                        Estimate          Std. Error  t value Pr(>|t|)
## (Intercept) -0.6055447455773891  2.0501076772804443 -0.29537  0.76783
## x            0.5127360382142074  1.0435967468264635  0.49132  0.62342
## I(x^2)      -0.0751773634412612  0.1485430319742770 -0.50610  0.61301
## I(x^3)       0.0032089963744107  0.0045640098932814  0.70311  0.48231
## 
## Residual standard error: 6.6824017464515997 on 502 degrees of freedom
## Multiple R-squared:  0.40003687202422,   Adjusted R-squared:  0.39645143500445 
## F-statistic: 111.57269527196 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $tax
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##               Min                1Q            Median                3Q 
## -13.2730275445485  -1.3891720336251   0.0456625600364   0.5360050624478 
##               Max 
##  76.9495700951911 
## 
## Coefficients:
##                         Estimate           Std. Error  t value Pr(>|t|)
## (Intercept)  1.9183581466934e+01  1.1795546491086e+01  1.62634  0.10450
## x           -1.5330961299173e-01  9.5678057374337e-02 -1.60235  0.10971
## I(x^2)       3.6082664616684e-04  2.4254627771577e-04  1.48766  0.13747
## I(x^3)      -2.2037151311693e-07  1.8887051581871e-07 -1.16679  0.24385
## 
## Residual standard error: 6.8537073690599 on 502 degrees of freedom
## Multiple R-squared:  0.36888207966296,   Adjusted R-squared:  0.36511045862509 
## F-statistic: 97.804651092733 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $ptratio
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##              Min               1Q           Median               3Q 
## -6.8334181714603 -4.1462619807084 -1.6548217553738  1.4076072966502 
##              Max 
## 82.6970935033851 
## 
## Coefficients:
##                        Estimate          Std. Error  t value  Pr(>|t|)   
## (Intercept) 477.184046102470688 156.794977501185116  3.04336 0.0024621 **
## x           -82.360537720755971  27.643942470939695 -2.97933 0.0030287 **
## I(x^2)        4.635347225616539   1.608321153573414  2.88210 0.0041196 **
## I(x^3)       -0.084760322418781   0.030897492258947 -2.74328 0.0063005 **
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 8.1215830269989002 on 502 degrees of freedom
## Multiple R-squared:  0.11378157744695,   Adjusted R-squared:  0.10848545141576 
## F-statistic: 21.483925566876 on 3 and 502 DF,  p-value: 4.1713144900396e-13
## 
## 
## $black
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##               Min                1Q            Median                3Q 
## -13.0962998882951  -2.3430458019337  -2.1280967498499  -1.4385817223205 
##               Max 
##  86.7903187877959 
## 
## Coefficients:
##                         Estimate           Std. Error  t value   Pr(>|t|)
## (Intercept)  1.8263700346007e+01  2.3049032642809e+00  7.92385 1.4971e-14
## x           -8.3558047490680e-02  5.6327509777117e-02 -1.48343    0.13859
## I(x^2)       2.1374036896543e-04  2.9841927193253e-04  0.71624    0.47418
## I(x^3)      -2.6524533116676e-07  4.3642636765405e-07 -0.60777    0.54362
##                
## (Intercept) ***
## x              
## I(x^2)         
## I(x^3)         
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 7.9546427351430999 on 502 degrees of freedom
## Multiple R-squared:  0.14983982880221,   Adjusted R-squared:  0.14475919032891 
## F-statistic: 29.492322586982 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $lstat
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##               Min                1Q            Median                3Q 
## -15.2335688128664  -2.1512725548201  -0.4864200593337   0.0657174964431 
##               Max 
##  83.3529752353371 
## 
## Coefficients:
##                         Estimate           Std. Error  t value Pr(>|t|)  
## (Intercept)  1.20096558118800822  2.02864515802087109  0.59200 0.554115  
## x           -0.44906558716479489  0.46489110921973897 -0.96596 0.334530  
## I(x^2)       0.05577941585471223  0.03011560719835643  1.85218 0.064587 .
## I(x^3)      -0.00085737033900152  0.00056516672120355 -1.51702 0.129891  
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 7.6294360930289002 on 502 degrees of freedom
## Multiple R-squared:  0.21793243242226,   Adjusted R-squared:  0.21325872185904 
## F-statistic:  46.62942419618 on 3 and 502 DF,  p-value: < 2.22044604925e-16
## 
## 
## $medv
## 
## Call:
## lm(formula = Boston$crim ~ x + I(x^2) + I(x^3))
## 
## Residuals:
##               Min                1Q            Median                3Q 
## -24.4265770495305  -1.9755086043100  -0.4366109107804   0.4388915832577 
##               Max 
##  73.6545621633528 
## 
## Coefficients:
##                         Estimate           Std. Error   t value   Pr(>|t|)
## (Intercept) 53.16553809437311884  3.35631053507376631  15.84047 < 2.22e-16
## x           -5.09483054344755804  0.43383205249650014 -11.74379 < 2.22e-16
## I(x^2)       0.15549649000059157  0.01719044221649928   9.04552 < 2.22e-16
## I(x^3)      -0.00149010277183318  0.00020378954152637  -7.31197 1.0465e-12
##                
## (Intercept) ***
## x           ***
## I(x^2)      ***
## I(x^3)      ***
## ---
## Signif. codes:    0 '***' 0.001 '**' 0.01 '*' 0.050000000000000003 '.'
##   0.10000000000000001 ' ' 1
## 
## Residual standard error: 6.5691520012923004 on 502 degrees of freedom
## Multiple R-squared:  0.42020025656342,   Adjusted R-squared:  0.41673531785762 
## F-statistic: 121.27206055925 on 3 and 502 DF,  p-value: < 2.22044604925e-16