Skip to content

glm code tweak #8

@tomdrake

Description

@tomdrake

Hello - Not one to rush into - I'll test over next couple of weeks, but as an update I've rewritten a few of the glm functions to be able to handle weights and potentially new families in models (so these are compatible with propensity score matching.

It produces the same glmlist model (albeit with a more accurate call per dependent variable).

I'll work on it a bit and see if it errors at all. Posted for the record!

Example:

glmmulti <- function(df.in, dependent, explanatory, weights = NULL, family = "binomial"){ result = list() if (is.null(weights)){ for (i in 1:length(dependent)) { f <- as.formula(paste(dependent, '~', paste(explanatory, collapse="+"))) fit <- do.call("glm", list(formula=f, data=df.in, family= family)) fit['call'] = deparse(f) result[[i]] <- fit} } else { for (i in 1:length(dependent)) { f <- as.formula(paste(dependent, '~', paste(explanatory, collapse="+"))) fit <- do.call("glm", list(formula=f, data=df.in, family= family, weights = weights)) fit['call'] = deparse(f) result[[i]] <- fit} } result = setNames(result, dependent) class(result) = "glmlist" return(result) }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions