Tietokoneharjoitus 2

              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
county          int    %9.0g                  county identifier
year            byte   %9.0g                  81 to 87
crmrte          float  %9.0g                  crimes committed per person
prbarr          float  %9.0g                  'probability' of arrest
prbconv         float  %9.0g                  'probability' of conviction
prbpris         float  %9.0g                  'probability' of prison sentenc
avgsen          float  %9.0g                  avg. sentence, days
polpc           float  %9.0g                  police per capita
density         float  %9.0g                  people per sq. mile
taxpc           float  %9.0g                  tax revenue per capita
west            byte   %9.0g                  =1 if in western N.C.
central         byte   %9.0g                  =1 if in central N.C.
urban           byte   %9.0g                  =1 if in SMSA
pctmin80        float  %9.0g                  perc. minority, 1980
wcon            float  %9.0g                  weekly wage, construction
wtuc            float  %9.0g                  wkly wge, trns, util, commun
wtrd            float  %9.0g                  wkly wge, whlesle, retail trade
wfir            float  %9.0g                  wkly wge, fin, ins, real est
wser            float  %9.0g                  wkly wge, service industry
wmfg            float  %9.0g                  wkly wge, manufacturing
wfed            float  %9.0g                  wkly wge, fed employees
wsta            float  %9.0g                  wkly wge, state employees
wloc            float  %9.0g                  wkly wge, local gov emps
mix             float  %9.0g                  offense mix: face-to-face/other
pctymle         float  %9.0g                  percent young male
d82             byte   %9.0g                  =1 if year == 82
d83             byte   %9.0g                  =1 if year == 83
d84             byte   %9.0g                  =1 if year == 84
d85             byte   %9.0g                  =1 if year == 85
d86             byte   %9.0g                  =1 if year == 86
d87             byte   %9.0g                  =1 if year == 87
lcrmrte         float  %9.0g                  log(crmrte)
lprbarr         float  %9.0g                  log(prbarr)
lprbconv        float  %9.0g                  log(prbconv)
lprbpris        float  %9.0g                  log(prbpris)
lavgsen         float  %9.0g                  log(avgsen)
lpolpc          float  %9.0g                  log(polpc)
ldensity        float  %9.0g                  log(density)
ltaxpc          float  %9.0g                  log(taxpc)
lwcon           float  %9.0g                  log(wcon)
lwtuc           float  %9.0g                  log(wtuc)
lwtrd           float  %9.0g                  log(wtrd)
lwfir           float  %9.0g                  log(wfir)
lwser           float  %9.0g                  log(wser)
lwmfg           float  %9.0g                  log(wmfg)
lwfed           float  %9.0g                  log(wfed)
lwsta           float  %9.0g                  log(wsta)
lwloc           float  %9.0g                  log(wloc)
lmix            float  %9.0g                  log(mix)
lpctymle        float  %9.0g                  log(pctymle)
lpctmin         float  %9.0g                  log(pctmin)
clcrmrte        float  %9.0g                  lcrmrte - lcrmrte[_n-1]
clprbarr        float  %9.0g                  lprbarr - lprbarr[_n-1]
clprbcon        float  %9.0g                  lprbconv - lprbconv[_n-1]
clprbpri        float  %9.0g                  lprbpri - lprbpri[t-1]
clavgsen        float  %9.0g                  lavgsen - lavgsen[t-1]
clpolpc         float  %9.0g                  lpolpc - lpolpc[t-1]
cltaxpc         float  %9.0g                  ltaxpc - ltaxpc[t-1]
clmix           float  %9.0g                  lmix - lmix[t-1]

Tehtävä 5

Estimoi regressiomalli vuoden 1987 aineistolle, jossa y-muuttuja on log(crmrte) (logarithm of crimes committed per person) ja selittavat muuttujat ovat log(prbarr), log(prbconv), log(prbpris) ja log(avgsen).

file<-"http://cc.oulu.fi/~jklemela/panel/cornwell.raw"
data<-read.table(file=file)

year<-data[,2]
ind<-(year==87)
y<-log(data[ind,3])

x1<-log(data[ind,4])
x2<-log(data[ind,5])
x3<-log(data[ind,6])
x4<-log(data[ind,7])

reg.model<-lm(y ~ x1+x2+x3+x4)

summary(reg.model)

Call:
lm(formula = y ~ x1 + x2 + x3 + x4)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.36104 -0.19129  0.07939  0.27754  0.86843 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4.86792    0.43153 -11.281  < 2e-16 ***
x1          -0.72397    0.11532  -6.278 1.39e-08 ***
x2          -0.47251    0.08311  -5.686 1.80e-07 ***
x3           0.15967    0.20644   0.773    0.441    
x4           0.07642    0.16347   0.467    0.641    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.429 on 85 degrees of freedom
Multiple R-squared: 0.4162,	Adjusted R-squared: 0.3888 
F-statistic: 15.15 on 4 and 85 DF,  p-value: 2.171e-09 

-----------------------------------------------------------
R2<-0.4162
N<-90
K<-5
R2/(1-R2)*(N-K)/(K-1)

[1] 15.14945

Lisataan selittava muuttuja vuoden 1986 log(crmrte).

year<-data[,2]
ind<-(year==87)
y<-log(data[ind,3])

x1<-log(data[ind,4])
x2<-log(data[ind,5])
x3<-log(data[ind,6])
x4<-log(data[ind,7])
x5<-log(data[(year==86),3])

reg.model<-lm(y ~ x1+x2+x3+x4+x5)

summary(reg.model)

all:
lm(formula = y ~ x1 + x2 + x3 + x4 + x5)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.28022 -0.08931  0.03055  0.11019  0.32422 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.76663    0.31310  -2.449  0.01643 *  
x1          -0.18504    0.06276  -2.948  0.00414 ** 
x2          -0.03868    0.04660  -0.830  0.40891    
x3          -0.12669    0.09885  -1.282  0.20351    
x4          -0.15202    0.07829  -1.942  0.05552 .  
x5           0.77981    0.04521  17.248  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.2025 on 84 degrees of freedom
Multiple R-squared: 0.8715,	Adjusted R-squared: 0.8638 
F-statistic: 113.9 on 5 and 84 DF,  p-value: < 2.2e-16 

FILENAME myurl URL 'http://cc.oulu.fi/~jklemela/panel/cornwell.raw';

DATA cornwell;
   INFILE myurl firstobs=1;
   INPUT county year crmrte prbarr prbconv prbpris avgsen;
RUN;

PROC reg data=cornwell;
  model crmrte = prbarr prbconv prbpris avgsen;
RUN;

N<-length(y) K<-5 x<-matrix(1,N,K) x[,1]<-x1 x[,2]<-x2 x[,3]<-x3 x[,4]<-x4