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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/estimate.default.R
\name{estimate.default}
\alias{estimate.default}
\alias{estimate}
\alias{estimate.estimate}
\alias{merge.estimate}
\title{Estimation of functional of parameters}
\usage{
\method{estimate}{default}(
x = NULL,
f = NULL,
...,
data,
id,
iddata,
stack = TRUE,
average = FALSE,
subset,
score.deriv,
level = 0.95,
IC = robust,
type = c("robust", "df", "mbn"),
keep,
use,
regex = FALSE,
contrast,
null,
vcov,
coef,
robust = TRUE,
df = NULL,
print = NULL,
labels,
label.width,
only.coef = FALSE,
back.transform = NULL,
folds = 0,
cluster,
R = 0,
null.sim
)
}
\arguments{
\item{x}{model object (\code{glm}, \code{lvmfit}, ...)}
\item{f}{transformation of model parameters and (optionally) data, or contrast matrix (or vector)}
\item{...}{additional arguments to lower level functions}
\item{data}{\code{data.frame}}
\item{id}{(optional) id-variable corresponding to ic decomposition of model parameters.}
\item{iddata}{(optional) id-variable for 'data'}
\item{stack}{if TRUE (default) the i.i.d. decomposition is automatically stacked according to 'id'}
\item{average}{if TRUE averages are calculated}
\item{subset}{(optional) subset of data.frame on which to condition (logical expression or variable name)}
\item{score.deriv}{(optional) derivative of mean score function}
\item{level}{level of confidence limits}
\item{IC}{if TRUE (default) the influence function decompositions are also returned (extract with \code{IC} method)}
\item{type}{type of small-sample correction}
\item{keep}{(optional) index of parameters to keep from final result}
\item{use}{(optional) index of parameters to use in calculations}
\item{regex}{If TRUE use regular expression (perl compatible) for keep,use arguments}
\item{contrast}{(optional) Contrast matrix for final Wald test}
\item{null}{(optional) null hypothesis to test}
\item{vcov}{(optional) covariance matrix of parameter estimates (e.g. Wald-test)}
\item{coef}{(optional) parameter coefficient}
\item{robust}{if TRUE robust standard errors are calculated. If
FALSE p-values for linear models are calculated from t-distribution}
\item{df}{degrees of freedom (default obtained from 'df.residual')}
\item{print}{(optional) print function}
\item{labels}{(optional) names of coefficients}
\item{label.width}{(optional) max width of labels}
\item{only.coef}{if TRUE only the coefficient matrix is return}
\item{back.transform}{(optional) transform of parameters and confidence intervals}
\item{folds}{(optional) aggregate influence functions (divide and conquer)}
\item{cluster}{(obsolete) alias for 'id'.}
\item{R}{Number of simulations (simulated p-values)}
\item{null.sim}{Mean under the null for simulations}
}
\description{
Estimation of functional of parameters.
Wald tests, robust standard errors, cluster robust standard errors,
LRT (when \code{f} is not a function)...
}
\details{
influence function decomposition
\deqn{\sqrt{n}(\widehat{\theta}-\theta) = \sum_{i=1}^n\epsilon_i + o_p(1)}
can be extracted with the \code{IC} method.
}
\examples{
## 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 cbind(0,1,-1)
estimate(g,as.list(2:3)) ## same as rbind(c(0,1,0),c(0,0,1))
## Alternative syntax
estimate(g,"z","z"-"x",2*"z"-3*"x")
estimate(g,z,z-x,2*z-3*x)
estimate(g,"?") ## Wildcards
estimate(g,"*Int*","z")
estimate(g,"1","2"-"3",null=c(0,1))
estimate(g,2,3)
## Usual (non-robust) confidence intervals
estimate(g,robust=FALSE)
## 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,seed=1)
e <- estimate(list(m,m),list(d1,d2))
estimate(e) ## Wrong
ee <- estimate(e, id=rep(seq(nrow(d1)), 2)) ## Clustered
ee
estimate(lm(y~x,d1))
## Marginalize
f <- function(p,data)
list(p0=lava:::expit(p["(Intercept)"] + p["z"]*data[,"z"]),
p1=lava:::expit(p["(Intercept)"] + p["x"] + p["z"]*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
IC(estimate(l1,id=id1,stack=FALSE))
IC(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))
## If all models were estimated on the same data we could use the
## syntax:
## Reduce(merge,estimate(list(l1,l2,l3)))
## Same:
IC(a1 <- merge(l1,l2,l3,id=list(id1,id2,id3)))
IC(merge(l1,l2,l3,id=TRUE)) # one-to-one (same clusters)
IC(merge(l1,l2,l3,id=FALSE)) # independence
## Monte Carlo approach, simple trend test example
m <- categorical(lvm(),~x,K=5)
regression(m,additive=TRUE) <- y~x
d <- simulate(m,100,seed=1,'y~x'=0.1)
l <- lm(y~-1+factor(x),data=d)
f <- function(x) coef(lm(x~seq_along(x)))[2]
null <- rep(mean(coef(l)),length(coef(l))) ## just need to make sure we simulate under H0: slope=0
estimate(l,f,R=1e2,null.sim=null)
estimate(l,f)
}
|