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

gbm.plot: y axis values reported incorrectly to plot.default? #41

Open
SimonDedman opened this issue May 18, 2023 · 0 comments
Open

gbm.plot: y axis values reported incorrectly to plot.default? #41

SimonDedman opened this issue May 18, 2023 · 0 comments

Comments

@SimonDedman
Copy link

Hi folks, sorry for the multiple recent messages.

In my package, I call gbm.plot, and was looking to add a simple abline at 0:

png(filename = paste0("./",names(samples[i]),"/Gaus_Best_line_",as.character(get(Gaus_Best_Model)$gbm.call$predictor.names[p]),".png"),
            width = 4*480, height = 4*480, units = "px", pointsize = 80, bg = "white", res = NA, family = "", type = pngtype)
        par(mar = c(2.3,5,0.3,0.6), fig = c(0,1,0,1), las = 1, lwd = 8, bty = "n", mgp = c(1.25,0.5,0), xpd = NA)
        gbm.plot(get(Gaus_Best_Model),
                 variable.no = p,
                 n.plots = 1,
                 common.scale = FALSE, #added to try to get cvs values to match pngs
                 smooth = smooth, # typically TRUE
                 rug = TRUE,
                 write.title = FALSE,
                 y.label = "",
                 x.label = NULL,
                 show.contrib = TRUE,
                 plot.layout = c(1, 1))
        abline(a = 0, b = 0, lty = 2, lwd = 20) # https://github.com/SimonDedman/gbm.auto/issues/7
        mtext("Marginal Effect", side = 2, line = 4.05, las = 0)

I initially tried abline(h=0) which had the same result: regardless of input - which is otherwise plotting great - the abline is at the bottom:

Gaus_Best_line_X CC

In this example, Y crosses 0 both in the raw data, as well as when centred:

image

Somewhat regardless, all data should be centred due to these lines from gbm.plot:

response.matrix <- gbm::plot.gbm(gbm.object, k, return.grid = TRUE)
responses[[j]] <- response.matrix[, 2] - mean(response.matrix[, 2])
plot(predictors[[j]], responses[[j]], type = "l",  xlab = x.label, ylab = y.label, ...)

I've looked and looked and can't for the life of me work out why this isn't working. A simple abline call works fine:

plot(-5:5, -5:5)
abline(h=0)

On a whim, I tried adding ablines at 0, 0.5, 1, 2, 5, 10, 100, and get the following - the lines are in the same place for every plot regardless of changing Y axis scales, suggesting the underlying plot seemingly isn't operating on the standard plot scale somehow?

Gaus_Best_line_X CC

Any ideas or gut feelings very much appreciated.

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

No branches or pull requests

1 participant