Skip to content

Commit

Permalink
Some supports added for plm
Browse files Browse the repository at this point in the history
Does not fix #97
  • Loading branch information
jacob-long committed Apr 8, 2022
1 parent 9d1d715 commit 92f1ffb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ S3method(family,rq)
S3method(getCall,summ)
S3method(get_formula,brmsfit)
S3method(get_formula,default)
S3method(get_formula,panelmodel)
S3method(glance,summ.glm)
S3method(glance,summ.merMod)
S3method(glance,summ.svyglm)
Expand Down
13 changes: 13 additions & 0 deletions R/make_new_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ get_formula.brmsfit <- function(model, resp = NULL, dpar = NULL, ...) {
}
}

#' @rdname get_formula
#' @export
get_formula.panelmodel <- function(model, ...) {
f <- formula(model)
class(f) <- class(f) %not% "Formula"
f
}

get_family <- function(model, ...) {
UseMethod("get_family")
}
Expand Down Expand Up @@ -416,6 +424,11 @@ get_family.brmsfit <- function(model, resp = NULL, ...) {
}
}

#' @importFrom stats gaussian
get_family.plm <- function(model, ...) {
gaussian(link = "identity")
}

# formerly built into make_new_data, but I want to use it for other times
# when I just want the values of non-focal predictors
get_control_values <- function(model, data, preds, at, center, design = NULL,
Expand Down
8 changes: 4 additions & 4 deletions R/make_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ make_predictions.default <- function(model, pred, pred.values = NULL, at = NULL,
} else {pm <- new_data}


link_or_lm <- ifelse(family(model)$link == "identity",
link_or_lm <- ifelse(get_family(model)$link == "identity",
yes = "response", no = "link")

# Do the predictions using built-in prediction method if robust is FALSE
Expand Down Expand Up @@ -211,10 +211,10 @@ make_predictions.default <- function(model, pred, pred.values = NULL, at = NULL,
# Back-convert the predictions to the response scale
if (outcome.scale == "response") {
pm[[get_response_name(model)]] <-
family(model)$linkinv(pm[[get_response_name(model)]])
get_family(model)$linkinv(pm[[get_response_name(model)]])
if (interval == TRUE) {
pm[["ymax"]] <- family(model)$linkinv(pm[["ymax"]])
pm[["ymin"]] <- family(model)$linkinv(pm[["ymin"]])
pm[["ymax"]] <- get_family(model)$linkinv(pm[["ymax"]])
pm[["ymin"]] <- get_family(model)$linkinv(pm[["ymin"]])
}
}

Expand Down
3 changes: 3 additions & 0 deletions man/get_formula.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 92f1ffb

Please sign in to comment.