1 Vector

## [1] 1
## [1]  2  3  4  5  6  7  8  9 10
##  [1]  1  2  3  4  5  6  7  8  9 10
##  [1] 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571
##  [8] 0.1250000 0.1111111 0.1000000
##  [1]   1   4   9  16  25  36  49  64  81 100
##  [1]   2   5  10  17  26  37  50  65  82 101
##  [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 1.9459101
##  [8] 2.0794415 2.1972246 2.3025851
##  [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 1.9459101
##  [8] 2.0794415 2.1972246 2.3025851
##  [1]  10  20  30  40  50  60  70  80  90 100
##  [1]  11  22  33  44  55  66  77  88  99 110
##  [1]   10   40   90  160  250  360  490  640  810 1000
##  [1] 1.000000e+01 4.000000e+02 2.700000e+04 2.560000e+06 3.125000e+08
##  [6] 4.665600e+10 8.235430e+12 1.677722e+15 3.874205e+17 1.000000e+20
## [1] 9.166667
## [1] 9.166667
##  [1]  1  2  3  4  5  6  7  8  9 10
## [1] 2
## [1] 2 3
## [1] 3 2
## [1]  6  7  8  9 10
##  [1] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
## [1] 6 7 8 9
## [1]  1  2  9 10
##  [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 1.9459101
##  [8] 2.0794415 2.1972246 2.3025851
## [1] 1 2 3 4 5 6 7
##  [1]  3  3  3  3  3  3  3  8  9 10
##  [1]  0  1  2  3  4  5  6  7  8  9 10
##  [1]  0.0000000  0.5263158  1.0526316  1.5789474  2.1052632  2.6315789
##  [7]  3.1578947  3.6842105  4.2105263  4.7368421  5.2631579  5.7894737
## [13]  6.3157895  6.8421053  7.3684211  7.8947368  8.4210526  8.9473684
## [19]  9.4736842 10.0000000
##  [1]  1  2  3  4  5  6  7  8  9 10
## [1] 1 0
## [1] 1 2 3 4 5
##  [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
##  [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5

2 Strings

## [1] "a" "b" "c"
## [1] "ab"
## [1] "ab"
## [1] "a d" "b e" "c d"
## [1] "a 10" "b 10" "c 10"
## [1] "a10" "b10" "c10"
## [1] "a10" "b10" "c10"
##  [1] "a1"  "b2"  "c3"  "a4"  "b5"  "c6"  "a7"  "b8"  "c9"  "a10"
##  [1] "unit1.pdf"  "unit2.pdf"  "unit3.pdf"  "unit4.pdf"  "unit5.pdf" 
##  [6] "unit6.pdf"  "unit7.pdf"  "unit8.pdf"  "unit9.pdf"  "unit10.pdf"
##  [1] "unit1.html"  "unit2.html"  "unit3.html"  "unit4.html"  "unit5.html" 
##  [6] "unit6.html"  "unit7.html"  "unit8.html"  "unit9.html"  "unit10.html"
##  [1] "afig.pdf"                         "alist.RDS"                       
##  [3] "mixmodel.bug"                     "mixmodel.jags"                   
##  [5] "mtcars.csv"                       "mtcars.RData"                    
##  [7] "mtcars2.csv"                      "normmodel.bug"                   
##  [9] "numbers.txt"                      "oldRcode"                        
## [11] "rdemo.Rproj"                      "regmodel.bug"                    
## [13] "uni11-mcmc-intro.html"            "uni11-mcmc-intro.pdf"            
## [15] "uni11-mcmc-intro.Rmd"             "unit1-introduction_longer.html"  
## [17] "unit1-introduction_longer.pdf"    "unit1-introduction_longer.Rmd"   
## [19] "unit10-rejection sampling.Rmd"    "unit10-rejection_sampling_cache" 
## [21] "unit10-rejection_sampling_files"  "unit10-rejection_sampling.html"  
## [23] "unit10-rejection_sampling.pdf"    "unit11-importance-sampling_cache"
## [25] "unit11-importance-sampling_files" "unit11-importance-sampling.html" 
## [27] "unit11-importance-sampling.pdf"   "unit11-importance-sampling.Rmd"  
## [29] "unit12-gibbs_cache"               "unit12-gibbs_files"              
## [31] "unit12-gibbs.html"                "unit12-gibbs.pdf"                
## [33] "unit12-gibbs.Rmd"                 "unit14-MHsampling.html"          
## [35] "unit14-MHsampling.pdf"            "unit14-MHsampling.Rmd"           
## [37] "unit15-jags_cache"                "unit15-jags_files"               
## [39] "unit15-jags.html"                 "unit15-jags.pdf"                 
## [41] "unit15-jags.Rmd"                  "unit16-stan_cache"               
## [43] "unit16-stan_files"                "unit16-stan.html"                
## [45] "unit16-stan.pdf"                  "unit16-stan.Rmd"                 
## [47] "unit2-comparith.html"             "unit2-comparith.pdf"             
## [49] "unit2-comparith.Rmd"              "unit3-sampling_basics.html"      
## [51] "unit3-sampling_basics.pdf"        "unit3-sampling_basics.Rmd"       
## [53] "unit4-simulation_cache"           "unit4-simulation_files"          
## [55] "unit4-simulation.html"            "unit4-simulation.pdf"            
## [57] "unit4-simulation.Rmd"             "unit5-MLE1_cache"                
## [59] "unit5-MLE1.html"                  "unit5-MLE1.pdf"                  
## [61] "unit5-MLE1.Rmd"                   "unit6-MLEm.html"                 
## [63] "unit6-MLEm.pdf"                   "unit6-MLEm.Rmd"                  
## [65] "unit7-em.html"                    "unit7-em.pdf"                    
## [67] "unit7-em.Rmd"                     "unit8-integral.html"             
## [69] "unit8-integral.pdf"               "unit8-integral.Rmd"              
## [71] "unit9-laplace_cache"              "unit9-laplace.html"              
## [73] "unit9-laplace.pdf"                "unit9-laplace.Rmd"               
## [75] "y.txt"
##  [1] "afig.pdf"                       "uni11-mcmc-intro.pdf"          
##  [3] "unit1-introduction_longer.pdf"  "unit10-rejection_sampling.pdf" 
##  [5] "unit11-importance-sampling.pdf" "unit12-gibbs.pdf"              
##  [7] "unit14-MHsampling.pdf"          "unit15-jags.pdf"               
##  [9] "unit16-stan.pdf"                "unit2-comparith.pdf"           
## [11] "unit3-sampling_basics.pdf"      "unit4-simulation.pdf"          
## [13] "unit5-MLE1.pdf"                 "unit6-MLEm.pdf"                
## [15] "unit7-em.pdf"                   "unit8-integral.pdf"            
## [17] "unit9-laplace.pdf"
##  [1] "uni11-mcmc-intro.Rmd"           "unit1-introduction_longer.Rmd" 
##  [3] "unit10-rejection sampling.Rmd"  "unit11-importance-sampling.Rmd"
##  [5] "unit12-gibbs.Rmd"               "unit14-MHsampling.Rmd"         
##  [7] "unit15-jags.Rmd"                "unit16-stan.Rmd"               
##  [9] "unit2-comparith.Rmd"            "unit3-sampling_basics.Rmd"     
## [11] "unit4-simulation.Rmd"           "unit5-MLE1.Rmd"                
## [13] "unit6-MLEm.Rmd"                 "unit7-em.Rmd"                  
## [15] "unit8-integral.Rmd"             "unit9-laplace.Rmd"
##  [1] "unit1-introduction_longer.html"   "unit1-introduction_longer.pdf"   
##  [3] "unit1-introduction_longer.Rmd"    "unit10-rejection sampling.Rmd"   
##  [5] "unit10-rejection_sampling_cache"  "unit10-rejection_sampling_files" 
##  [7] "unit10-rejection_sampling.html"   "unit10-rejection_sampling.pdf"   
##  [9] "unit11-importance-sampling_cache" "unit11-importance-sampling_files"
## [11] "unit11-importance-sampling.html"  "unit11-importance-sampling.pdf"  
## [13] "unit11-importance-sampling.Rmd"   "unit12-gibbs_cache"              
## [15] "unit12-gibbs_files"               "unit12-gibbs.html"               
## [17] "unit12-gibbs.pdf"                 "unit12-gibbs.Rmd"                
## [19] "unit14-MHsampling.html"           "unit14-MHsampling.pdf"           
## [21] "unit14-MHsampling.Rmd"            "unit15-jags_cache"               
## [23] "unit15-jags_files"                "unit15-jags.html"                
## [25] "unit15-jags.pdf"                  "unit15-jags.Rmd"                 
## [27] "unit16-stan_cache"                "unit16-stan_files"               
## [29] "unit16-stan.html"                 "unit16-stan.pdf"                 
## [31] "unit16-stan.Rmd"                  "unit2-comparith.html"            
## [33] "unit2-comparith.pdf"              "unit2-comparith.Rmd"             
## [35] "unit3-sampling_basics.html"       "unit3-sampling_basics.pdf"       
## [37] "unit3-sampling_basics.Rmd"        "unit4-simulation_cache"          
## [39] "unit4-simulation_files"           "unit4-simulation.html"           
## [41] "unit4-simulation.pdf"             "unit4-simulation.Rmd"            
## [43] "unit5-MLE1_cache"                 "unit5-MLE1.html"                 
## [45] "unit5-MLE1.pdf"                   "unit5-MLE1.Rmd"                  
## [47] "unit6-MLEm.html"                  "unit6-MLEm.pdf"                  
## [49] "unit6-MLEm.Rmd"                   "unit7-em.html"                   
## [51] "unit7-em.pdf"                     "unit7-em.Rmd"                    
## [53] "unit8-integral.html"              "unit8-integral.pdf"              
## [55] "unit8-integral.Rmd"               "unit9-laplace_cache"             
## [57] "unit9-laplace.html"               "unit9-laplace.pdf"               
## [59] "unit9-laplace.Rmd"
##  [1] "unit1-introduction_longer.pdf"  "unit10-rejection_sampling.pdf" 
##  [3] "unit11-importance-sampling.pdf" "unit12-gibbs.pdf"              
##  [5] "unit14-MHsampling.pdf"          "unit15-jags.pdf"               
##  [7] "unit16-stan.pdf"                "unit2-comparith.pdf"           
##  [9] "unit3-sampling_basics.pdf"      "unit4-simulation.pdf"          
## [11] "unit5-MLE1.pdf"                 "unit6-MLEm.pdf"                
## [13] "unit7-em.pdf"                   "unit8-integral.pdf"            
## [15] "unit9-laplace.pdf"
##  [1] "unit1-introduction_longer.html"  "unit10-rejection_sampling.html" 
##  [3] "unit11-importance-sampling.html" "unit12-gibbs.html"              
##  [5] "unit14-MHsampling.html"          "unit15-jags.html"               
##  [7] "unit16-stan.html"                "unit2-comparith.html"           
##  [9] "unit3-sampling_basics.html"      "unit4-simulation.html"          
## [11] "unit5-MLE1.html"                 "unit6-MLEm.html"                
## [13] "unit7-em.html"                   "unit8-integral.html"            
## [15] "unit9-laplace.html"

3 Special Values

## [1] NaN
## [1] TRUE
## [1] -Inf
## [1] FALSE
## [1]  0  1  2  3  4 NA
## [1] FALSE FALSE FALSE FALSE FALSE  TRUE

4 Matrices

##      [,1] [,2] [,3] [,4] [,5]
## [1,]    0    0    0    0    0
## [2,]    0    0    0    0    0
## [3,]    0    0    0    0    0
## [4,]    0    0    0    0    0
## [1] 1
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    5    9   13   17
## [2,]    2    6   10   14   18
## [3,]    3    7   11   15   19
## [4,]    4    8   12   16   20
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,]    1 1001 1003   13   17    1    5    9   13    17
## [2,]    2    6   10   14   18    2    6   10   14    18
## [3,]    3    7   11   15   19    3    7   11   15    19
## [4,]    4 1002 1004   16   20    4    8   12   16    20
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1 1001 1003   13   17
## [2,]    2    6   10   14   18
## [3,]    3    7   11   15   19
## [4,]    4 1002 1004   16   20
## [5,]    1    5    9   13   17
## [6,]    2    6   10   14   18
## [7,]    3    7   11   15   19
## [8,]    4    8   12   16   20
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3    4
## [2,] 1001    6    7 1002
## [3,] 1003   10   11 1004
## [4,]   13   14   15   16
## [5,]   17   18   19   20
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1 1001 1003   13   17
## [2,]    2    6   10   14   18
## [3,]    3    7   11   15   19
## [4,]    4 1002 1004   16   20
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2 1002 1004   14   18
## [2,]    3    7   11   15   19
## [3,]    4    8   12   16   20
## [4,]    5 1003 1005   17   21
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1 5005 4012   39   34
## [2,]    4    6   50   56   54
## [3,]    9   14   11   75   76
## [4,]   16 3006 2008   16  100
## Warning in A * x: longer object length is not a multiple of shorter object
## length
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1 2002 3009   13   34
## [2,]    4   18   10   28   54
## [3,]    9    7   22   45   19
## [4,]    4 2004 3012   16   40
##      [,1]    [,2]    [,3] [,4] [,5]
## [1,]    1 1002001 1006009  169  289
## [2,]    4      36     100  196  324
## [3,]    9      49     121  225  361
## [4,]   16 1004004 1008016  256  400
##      [,1] [,2] [,3] [,4] [,5]
## [1,]   11   19   16   18   13
## [2,]   12    1   10    6   17
## [3,]    8    2    5   14    3
## [4,]    9    4    7   15   20
##      [,1] [,2] [,3] [,4]
## [1,]   13   12    3   11
## [2,]    7    5    2    6
## [3,]   18    9   19   15
## [4,]   20   10   16    4
## [5,]    8   17   14    1
##      [,1] [,2] [,3] [,4]
## [1,] 1028  772  845  560
## [2,]  599  588  562  329
## [3,]  512  342  389  234
## [4,]  731  681  688  308
##              [,1]        [,2]        [,3]         [,4]
## [1,] -0.013504207  0.01024160  0.02775302 -0.007471873
## [2,] -0.019434017  0.02618275  0.02513969 -0.011732992
## [3,]  0.029873141 -0.03766748 -0.04945898  0.023496893
## [4,]  0.008290325  0.00194210 -0.01097341 -0.005564142
##      [,1]
## [1,]    1
## [2,]    2
## [3,]    3
## [4,]    4
##      [,1]
## [1,]    1
## [2,]    2
## [3,]    3
## [4,]    4
## $d
## [1] 2435.92651  149.22300   66.41318   11.03789
## 
## $u
##            [,1]       [,2]       [,3]       [,4]
## [1,] -0.6711792  0.5655668  0.2176879  0.4269246
## [2,] -0.4351502 -0.3795141  0.6395932 -0.5074780
## [3,] -0.3128970  0.3590293 -0.5464474 -0.6889039
## [4,] -0.5121116 -0.6381231 -0.4949018  0.2925968
## 
## $v
##            [,1]       [,2]       [,3]        [,4]
## [1,] -0.6096998  0.4786713 -0.5218061 -0.35617160
## [2,] -0.5048500 -0.6588161  0.3044986 -0.46729915
## [3,] -0.5278281 -0.2328679 -0.1454956  0.80374190
## [4,] -0.3078800  0.5316086  0.7834730  0.09366034
## [1] 266465184

5 Data frame

## [1] m m f
## Levels: f m
## [1] m m f
## Levels: f m
## [1] m
## Levels: f m
## [1] john     peter    jennifer
## Levels: jennifer john peter
## [1] john     peter    jennifer
## Levels: jennifer john peter
##    name gender hw1 hw2
## 1  john      m  60  40
## 2 peter      m  60  50
##       name gender hw1 hw2
## 3 jennifer      f  80  30
## [1] 60 60 80
##  f  m 
## 80 60

6 List

## [1] "aa" "b"  "c"
## List of 3
##  $ aa: int [1:10] 1 2 3 4 5 6 7 8 9 10
##  $ b : int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10
##  $ c : chr [1:2] "name1" "name2"
##  [1]  1  2  3  4  5  6  7  8  9 10
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    3    5    7    9
## [2,]    2    4    6    8   10
## $aa
##  [1]  1  2  3  4  5  6  7  8  9 10
## 
## $b
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    3    5    7    9
## [2,]    2    4    6    8   10
## 
## $c
## [1] "name1" "name2"
## 
## $d
## [1]  20  30  40  50  60  70  80  90 100

7 Reading and saving data to harddrive

## [1] TRUE

8 Function

## [1] -0.8164405 -1.1380846  0.4119581  1.0526453 -1.4973434
## $max
## [1] 1.052645
## 
## $index.max
## [1] 4
## [1] 1.052645
## [1] 4
## [1] 5 2 1 3 4
## [1] -1.4973434 -1.1380846 -0.8164405  0.4119581  1.0526453
## $x
## [1] -1.4973434 -1.1380846 -0.8164405  0.4119581  1.0526453
## 
## $ix
## [1] 5 2 1 3 4

9 Graphics

## quartz_off_screen 
##                 2