+measerr_mle_dv <- function(df, outcome_formula, outcome_family=binomial(link='logit'), proxy_formula, proxy_family=binomial(link='logit'),maxit=1e6, method='optim',optim_method='L-BFGS-B'){
+ df.obs <- model.frame(outcome_formula, df)
+ proxy.model.matrix <- model.matrix(proxy_formula, df)
+ proxy.variable <- all.vars(proxy_formula)[1]
+
+ df.proxy.obs <- model.frame(proxy_formula,df)
+ proxy.obs <- with(df.proxy.obs, eval(parse(text=proxy.variable)))
+
+ response.var <- all.vars(outcome_formula)[1]
+ y.obs <- with(df.obs,eval(parse(text=response.var)))
+ outcome.model.matrix <- model.matrix(outcome_formula, df.obs)
+
+ df.unobs <- df[is.na(df[[response.var]])]
+ df.unobs.y1 <- copy(df.unobs)
+ df.unobs.y1[[response.var]] <- 1
+ df.unobs.y0 <- copy(df.unobs)
+ df.unobs.y0[[response.var]] <- 0
+
+ outcome.model.matrix.y1 <- model.matrix(outcome_formula, df.unobs.y1)
+ proxy.model.matrix.y1 <- model.matrix(proxy_formula, df.unobs.y1)
+ proxy.model.matrix.y0 <- model.matrix(proxy_formula, df.unobs.y0)
+ proxy.unobs <- with(df.unobs, eval(parse(text=proxy.variable)))