Thuis
Contacten

    Hoofdpagina


Docent: drs. Rob Flohr

Dovnload 2 Mb.

Docent: drs. Rob Flohr



Pagina13/25
Datum05.12.2018
Grootte2 Mb.

Dovnload 2 Mb.
1   ...   9   10   11   12   13   14   15   16   ...   25

> plot(beers,bac)


b)
> lm(bac~beers)


Call:

lm(formula = bac ~ beers)


Coefficients:

(Intercept) beers



-0.01270 0.01796


> regres=lm(bac~beers)

> abline(regres)



c)
> cor(beers,bac)

[1] 0.8943381



> 0.8943381^2

[1] 0.7998406


d)
Not surprisingly, we find that BAC increases as BAC increases; the consumption of beer explains 80% of the variation in BAC.


e)
> model=lm(bac~beers)



> summary(model)
Call:

lm(formula = bac ~ beers)


Residuals:

Min 1Q Median 3Q Max

-0.027118 -0.017350 0.001773 0.008623 0.041027
Coefficients:

Estimate Std. Error t value Pr(>|t|)



(Intercept) -0.012701 0.012638 -1.005 0.332

beers 0.017964 0.002402 7.480 2.97e-06 ***

---


Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.02044 on 14 degrees of freedom

Multiple R-squared: 0.7998, Adjusted R-squared: 0.7855

F-statistic: 55.94 on 1 and 14 DF, p-value: 2.969e-06
> confint(model)

2.5 % 97.5 %

(Intercept) -0.03980535 0.01440414

beers 0.01281262 0.02311490



> summary.aov(model)

Df Sum Sq Mean Sq F value Pr(>F)

beers 1 0.02337 0.023375 55.94 2.97e-06 ***

Residuals 14 0.00585 0.000418

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1



N.B. 0.02337/(0.02337+0.00585)=0.7998

>


Conclusion: there is very strong evidence that drinking more beers increases BAC in the population)

------------------------------------------------------------------------------

Uitwerking b) m.b.v. MCMCpack in R:

R version 2.15.2 (2012-10-26) -- "Trick or Treat"

Copyright (C) 2012 The R Foundation for Statistical Computing

ISBN 3-900051-07-0

Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.

You are welcome to redistribute it under certain conditions.

Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.

Type 'contributors()' for more information and

'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or

'help.start()' for an HTML browser interface to help.

Type 'q()' to quit R.
[Previously saved workspace restored]
> utils:::menuInstallPkgs()

--- Please select a CRAN mirror for use in this session ---

trying URL 'http://cran-mirror.cs.uu.nl/bin/windows/contrib/2.15/MCMCpack_1.3-3.zip'

Content type 'application/zip' length 2950090 bytes (2.8 Mb)

opened URL

downloaded 2.8 Mb


package ‘MCMCpack’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in

C:\Users\Eigenaar\AppData\Local\Temp\RtmpuchU0P\downloaded_packages

> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)

+ if(nchar(pkg)) library(pkg, character.only=TRUE)})

Loading required package: coda

Loading required package: lattice

Loading required package: MASS

##

## Markov Chain Monte Carlo Package (MCMCpack)



## Copyright (C) 2003-2014 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park

##

## Support provided by the U.S. National Science Foundation



## (Grants SES-0350646 and SES-0350613)

##

Warning messages:



1: package ‘MCMCpack’ was built under R version 2.15.3

2: package ‘coda’ was built under R version 2.15.3



> library(MCMCpack)

> help(package=MCMCpack)

starting httpd help server ... done

> beers=c(5,2,9,8,3,7,3,5,3,5,4,6,5,7,1,4)

> bac=c(0.10,0.03,0.19,0.12,0.04,0.095,0.07,0.06,0.02,0.05,0.07,0.10,0.085,0.09,0.01,0.05)

> m=data.frame(beers,bac)

> m

beers bac

1 5 0.100

2 2 0.030

3 9 0.190

4 8 0.120

5 3 0.040

6 7 0.095

7 3 0.070

8 5 0.060

9 3 0.020

10 5 0.050

11 4 0.070

12 6 0.100

13 5 0.085

14 7 0.090

15 1 0.010

16 4 0.050



> m6=MCMCregress(bac~beers,data=m)

> summary(m6)
Iterations = 1001:11000

Thinning interval = 1

Number of chains = 1

Sample size per chain = 10000


1. Empirical mean and standard deviation for each variable,

plus standard error of the mean:


Mean SD Naive SE Time-series SE

(Intercept) -0.0124923 0.014940 1.494e-04 1.470e-04

beers 0.0179221 0.002848 2.848e-05 2.773e-05
2. Quantiles for each variable:
2.5% 25% 50% 75% 97.5%

(Intercept) -0.0417037 -0.0219154 -0.0124212 -0.0031053 0.017676



(de nul-waarde zit in het 95%-interval, dus niet significant)


beers 0.0122021 0.0161481 0.0179487 0.0197013 0.023553



(de nul-waarde zit niet in het 95%-interval, dus wel significant)






> plot(m6,trace=FALSE)

>


Huiswerkopgave voor les 5 op 27 mei 2014

(1)
Schat m.b.v. WinBUGS de betreffende populatieproportie :


A survey of 13.819 students In U.S. four-year colleges collected information on drinking behavior and alcohol-related problems. According to some definition, 3140 students were classified as frequent binge drinkers.

Uitwerking:


1   ...   9   10   11   12   13   14   15   16   ...   25

  • > lm(bacbeers) Call: lm(formula = bac beers) Coefficients: (Intercept) beers -0.01270 0.01796 > regres=lm(bacbeers)
  • > cor(beers,bac)
  • (Intercept) -0.012701 0.012638 -1.005 0.332 beers 0.017964 0.002402 7.480 2.97e-06 ***
  • 0.7998
  • > library(MCMCpack)
  • > m6=MCMCregress(bacbeers,data=m) > summary(m6)
  • -0.0124923
  • 0.0122021 0.0161481 0.0179487 0.0197013 0.023553 (de nul-waarde zit niet in het 95%-interval, dus wel significant)

  • Dovnload 2 Mb.