Description Usage Arguments Examples
View source: R/estimate.default.R
Estimation of functional of parameters.
Wald tests, robust standard errors, cluster robust standard errors,
LRT (when f
is not a function)...
1 2 3 4 5 |
x |
model object ( |
f |
transformation of model parameters and (optionally) data, or contrast matrix (or vector) |
data |
|
id |
(optional) id-variable corresponding to iid decomposition of model parameters. |
iddata |
(optional) id-variable for 'data' |
stack |
If TRUE (default) the i.i.d. decomposition is automatically stacked according to 'id' |
average |
If TRUE averages are calculated |
subset |
(optional) subset of data.frame on which to condition (logical expression or variable name) |
score.deriv |
(optional) derivative of mean score function |
level |
Level of confidence limits |
iid |
If TRUE (default) the iid decompositions are also returned (extract with |
type |
Type of small-sample correction |
keep |
(optional) Index of parameters to keep |
contrast |
(optional) Contrast matrix for final Wald test |
null |
(optional) Null hypothesis to test |
vcov |
(optional) covariance matrix of parameter estimates (e.g. Wald-test) |
coef |
(optional) parameter coefficient |
print |
(optional) print function |
labels |
(optional) names of coefficients |
... |
additional arguments to lower level functions |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | ## Simulation from logistic regression model
m <- lvm(y~x+z);
distribution(m,y~x) <- binomial.lvm("logit")
d <- sim(m,1000)
g <- glm(y~z+x,data=d,family=binomial())
g0 <- glm(y~1,data=d,family=binomial())
## LRT
estimate(g,g0)
## Plain estimates (robust standard errors)
estimate(g)
## Testing contrasts
estimate(g,null=0)
estimate(g,rbind(c(1,1,0),c(1,0,2)))
estimate(g,rbind(c(1,1,0),c(1,0,2)),null=c(1,2))
estimate(g,2:3) ## same as rbind(c(0,1,0),c(0,0,1))
## Transformations
estimate(g,function(p) p[1]+p[2])
## Multiple parameters
e <- estimate(g,function(p) c(p[1]+p[2],p[1]*p[2]))
e
vcov(e)
## Label new parameters
estimate(g,function(p) list("a1"=p[1]+p[2],"b1"=p[1]*p[2]))
## Multiple group
m <- lvm(y~x)
m <- baptize(m)
d2 <- d1 <- sim(m,50)
e <- estimate(list(m,m),list(d1,d2))
estimate(e) ## Wrong
estimate(e,id=rep(seq(nrow(d1)),2))
estimate(lm(y~x,d1))
## Marginalize
f <- function(p,data)
list(p0=lava:::expit(p[1] + p[3]*data[,"z"]),
p1=lava:::expit(p[1] + p[2] + p[3]*data[,"z"]))
e <- estimate(g, f, average=TRUE)
e
estimate(e,diff)
estimate(e,cbind(1,1))
## Clusters and subset (conditional marginal effects)
d$id <- rep(seq(nrow(d)/4),each=4)
estimate(g,function(p,data)
list(p0=lava:::expit(p[1] + p["z"]*data[,"z"])),
subset=d$z>0, id=d$id, average=TRUE)
## More examples with clusters:
m <- lvm(c(y1,y2,y3)~u+x)
d <- sim(m,10)
l1 <- glm(y1~x,data=d)
l2 <- glm(y2~x,data=d)
l3 <- glm(y3~x,data=d)
## Some random id-numbers
id1 <- c(1,1,4,1,3,1,2,3,4,5)
id2 <- c(1,2,3,4,5,6,7,8,1,1)
id3 <- seq(10)
## Un-stacked and stacked i.i.d. decomposition
iid(estimate(l1,id=id1,stack=FALSE))
iid(estimate(l1,id=id1))
## Combined i.i.d. decomposition
e1 <- estimate(l1,id=id1)
e2 <- estimate(l2,id=id2)
e3 <- estimate(l3,id=id3)
(a2 <- merge(e1,e2,e3))
## Same:
iid(a1 <- merge(l1,l2,l3,id=list(id1,id2,id3)))
iid(merge(l1,l2,l3,id=TRUE)) # one-to-one (same clusters)
iid(merge(l1,l2,l3,id=FALSE)) # independence
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.