Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #26

Merged
merged 5 commits into from
Nov 27, 2023
Merged

Dev #26

merged 5 commits into from
Nov 27, 2023

Conversation

LukaszChrostowski
Copy link
Member

No description provided.

@LukaszChrostowski LukaszChrostowski merged commit c5df762 into main Nov 27, 2023
6 checks passed
Copy link
Member

@Kertoo Kertoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments on residuals.nonprobsvy

@@ -346,19 +357,32 @@ cooks.distance.nonprobsvy <- function(model,
hatvalues.nonprobsvy <- function(model,
...) { # TODO reduce execution time and glm.fit object and customise to variable selection
if (any(c("nonprobsvy_dr", "nonprobsvy_ipw") %in% class(model))) {
X <- model$X
propensity_scores <- model$prob
W <- Matrix::Diagonal(x = propensity_scores * (1 - propensity_scores))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preety sure you can just leave W as a vector and this will work faster

}
#hats <- Matrix::Diagonal(x = W %*% object$X %*% XWX_inv %*% t(object$X))
#names(hat_values) <- row.names(model$parameters)
H <- as.matrix(sqrt(W) %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% sqrt(W))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you not just call hatvalues method on original engine like hatvalues.glm on glm's?

"pearsonSTD" = r/sqrt( (1 - hatvalues(object)$selection) * object$selection$variance)
) # TODO studentized_pearson, studentized_deviance
"pearsonSTD" = r/sqrt( (1 - hatvalues(object)$selection) * object$selection$variance),
stop("Invalid type of residual. Choose from 'pearson', 'working', 'deviance', 'response', 'pearsonSTD'.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this switch will result in base R error if type is NULL and will return NULL if type == NA probably doesn't matter here but its always good to remember that stop in switch can break if end user tries to break it :)

class = "family")
}

gaussian_nonprobsvy <- function(link = "identity") {
mu <- function(eta) eta
variance <- function(mu, y = NULL) rep.int(1, length(mu)) #mean((y - mu)^2) rep.int(1, length(mu))
variance <- function(mu, y = NULL) mean((y - mu)^2) #rep.int(1, length(mu)) rep.int(1, length(mu))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a reminder you don't have to write all those for every exponential family you want to use you can also just do something simpler like:

gaussian_nonprobsvy <- function(link = "identity") {
  x <- stats::gaussian(link = link)
  x$mu_der <- function(mu) 1
  # Sooner or later you will also probably need a class for those as well
  class(x) <- c(class(x), "nonprobsvy_family")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants