Professional Documents
Culture Documents
T Statistics HW-3 (Arefin-2824475)
T Statistics HW-3 (Arefin-2824475)
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Problem 1.17
Problem 1.19
Problem 1.21
Page 1 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Page 2 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Call:
lm(formula = age ~ circumference + Tree, data = Orange)
Residuals:
Min 1Q Median 3Q Max
-245.00 -93.69 -19.76 86.99 262.96
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -90.0596 55.5795 -1.620 0.116
Page 3 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Problem 1.23
+ for (j in 1:9){
+ if (s[i,j]>0) pool[i,j,-s[i,j]]=FALSE
+}
>
>
Problem 1.23(c)
In R, matrices (and arrays) are also considered as vectors. Hence s[i] represents the (1 + [(i -
1)/9], (i - 1) mod 9 + 1) entry of the grid.
Page 5 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
+ s[i]=(1:9)[pool[a,b,]]
+}
+ if (sum(pool[a,b,])==0){
+ print("wrong sudoku")
+ break()
+}
+}
+}
+}
>s
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 3 8 5 2 6 7 4 9
[2,] 2 7 9 3 4 1 8 5 6
[3,] 4 5 6 8 7 9 3 1 2
[4,] 7 4 2 6 3 5 1 9 8
[5,] 9 6 3 1 8 7 5 2 4
[6,] 5 8 1 4 9 2 6 7 3
[7,] 8 9 5 2 1 3 4 6 7
[8,] 3 1 7 9 6 4 2 8 5
[9,] 6 2 4 7 5 8 9 3 1
>
Problem 2.11
Page 6 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
> MYbinom<-function(s0,n0,p0){
+ cp=pbinom(c(0:n0),n0,p0)
+ X=array(0,c(s0,1))
+ for (i in 1:s0){
+ u=runif(1)
+ X[i]=sum(cp<u)
+}
+ return(X)
+}
> system.time(rbinom(5000,25,.2))
user system elapsed
0.00 0.00 0.02
> system.time(MYbinom(5000,25,.2))
user system elapsed
0.02 0.00 0.01
>
>
> #Problem 2.11(b)
> #==============
> Wait<-function(s0,alpha){
+ U=array(0,c(s0,1))
+ for (i in 1:s0){
+ u=runif(1)
Page 7 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Page 8 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Problem 2.12
Page 9 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
> a=3;b=2
> U1=matrix(runif(a*10^4),nrow=a)
> U2=matrix(runif(b*10^4),nrow=b)
> X1=apply(-log(U1),2,sum)
> X2=apply(-log(U2),2,sum)
> X=X1/(X1+X2)
> plot(function(x) dbeta(x,3,2),0,1)
> hist(X,freq=F,add=T,breaks=50)
Page 10 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Problem 2.12(b)
This is a consequence of F(x) = 1 - exp(-λx) being the Ɛxp(λ) cdf and of 1 - U being also
distributed as a U[0,1] random variable.
Problem 2.12(c)
This is due to the fact that F(x) = exp(x)/{1+exp(x)} is the cdf of the Logistic(0,1) distribution.
Problem 2.14
Page 11 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
>
>
> r=10;p=.01;spread=3*sqrt(r*(1-p)/p^2)
> t=round(seq(max(0,r*(1-p)/p-spread),r*(1-p)/p+spread,1))
> prob=pnbinom(t,r,p)
> range(prob)
[1] 2.341061e-10 9.932656e-01
>
Page 12 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Page 13 of 14
Bayesian Statistics
3470: 589-001
HW - 03 Mir Shahnewaz Arefin
Fall 2016 Student ID No: 2824475
Page 14 of 14