Showing posts with label quasi test. Show all posts
Showing posts with label quasi test. Show all posts

BinomialTreeOption

BinomialTreeOption

> CRRTree = BinomialTreeOption(TypeFlag = "pa", S = 50, X = 50,
+                              Time = 0.4167, r = 0.1, b = 0.1, sigma = 0.4, n = 5)
> BinomialTreePlot(CRRTree, dy = 1, cex = 0.8, ylim = c(-6, 7),
+                  xlab = "n", ylab = "Option Value")
> title(main = "Option Tree")
BinomialTreeOption
binom.test(c(682, 243), p = 3/4)

Exact binomial test

data:  c(682, 243)
number of successes = 682, number of
trials = 925, p-value = 0.3825
alternative hypothesis: true probability of success is not equal to 0.75
95 percent confidence interval:
 0.7076683 0.7654066
sample estimates:
probability of success 
             0.7372973 

Quasi test

> binom.test(682, 682 + 243, p = 3/4)

Exact binomial test

data:  682 and 682 + 243
number of successes = 682, number of
trials = 925, p-value = 0.3825
alternative hypothesis: true probability of success is not equal to 0.75
95 percent confidence interval:
 0.7076683 0.7654066
sample estimates:
probability of success 
             0.7372973 

> x <- rnorm(100)
> y <- rpois(100, exp(1+x))
> glm(y ~ x, family = quasi(variance = "mu", link = "log"))

Call:  glm(formula = y ~ x, family = quasi(variance = "mu", link = "log"))

Coefficients:
(Intercept)            x  
     1.0435       0.9478  

Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:     487.7 
Residual Deviance: 117 AIC: NA
> glm(y ~ x, family = poisson)

Call:  glm(formula = y ~ x, family = poisson)

Coefficients:
(Intercept)            x  
     1.0435       0.9478  

Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:     487.7 
Residual Deviance: 117 AIC: 389.7
> glm(y ~ x, family = quasi(variance = "mu^2", link = "log"))

Call:  glm(formula = y ~ x, family = quasi(variance = "mu^2", link = "log"))

Coefficients:
(Intercept)            x  
     1.0777       0.8539  

Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:     87.08 
Residual Deviance: 26.21 AIC: NA
> y <- rbinom(100, 1, plogis(x))
> glm(y ~ x, family = quasi(variance = "mu(1-mu)", link = "logit"), start = c(0,1))

Call:  glm(formula = y ~ x, family = quasi(variance = "mu(1-mu)", link = "logit"), 
    start = c(0, 1))

Coefficients:
(Intercept)            x  
    -0.5203       1.0420  

Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:     134.6 
Residual Deviance: 114.2 AIC: NA
> bi <- binomial()
> et <- seq(-10,10, by=1/8)
> plot(et, bi$mu.eta(et), type="l")