Skip to content

Commit

Permalink
Add example of 'quantreg' failure in inst-not
Browse files Browse the repository at this point in the history
  • Loading branch information
aphalo committed Jun 1, 2024
1 parent 94d139c commit f112f8f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
13 changes: 13 additions & 0 deletions inst-not/quantreg/ggplo2-quantreg-rqss.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library(ggplot2)

m <-
ggplot(mpg, aes(displ, 1 / hwy)) +
geom_point()
m + stat_quantile()

m + stat_quantile(method = "rqss")

m + stat_quantile(method = "rqss", lambda = 0.1)

sessionInfo()

25 changes: 25 additions & 0 deletions inst-not/quantreg/ggpmisc-quantreg-rqss.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library(ggplot2)
library(ggpmisc)

p <-
ggplot(mpg, aes(displ, 1 / hwy)) +
geom_point()
p + stat_quant_line()

p + stat_quant_line(method = "rqss")

p + stat_quant_line(method = "rqss", lambda = 0.1)

p + stat_quant_band()

p + stat_quant_band(method = "rqss")

p + stat_quant_band(method = "rqss", lambda = 0.1)

p + stat_quant_eq()

p + stat_quant_eq(method = "rqss")

p + stat_quant_eq(method = "rqss", lambda = 0.1)

sessionInfo()
29 changes: 29 additions & 0 deletions inst-not/quantreg/quantreg-rqss-examples.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library(quantreg)

n <- 200
x <- sort(rchisq(n,4))
z <- x + rnorm(n)
y <- log(x)+ .1*(log(x))^2 + log(x)*rnorm(n)/4 + z
plot(x, y-z)

f.N <- rqss(y ~ qss(x, constraint= "N") + z)

f.I <- rqss(y ~ qss(x, constraint= "I") + z)

f.CI <- rqss(y ~ qss(x, constraint= "CI") + z)

lines(x[-1], f.N $coef[1] + f.N $coef[-(1:2)])

lines(x[-1], f.I $coef[1] + f.I $coef[-(1:2)], col="blue")

lines(x[-1], f.CI$coef[1] + f.CI$coef[-(1:2)], col="red")

## A bivariate example
if(requireNamespace("interp")){
if(requireNamespace("interp")){
data(CobarOre)
fCO <- rqss(z ~ qss(cbind(x,y), lambda= .08), data=CobarOre)
plot(fCO)
}}

sessionInfo()
2 changes: 1 addition & 1 deletion tests/testthat/test-eq-label-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test_that("polynomial as character well formatted", {
expect_equal(poly2character(x = (1:5) * 1e-6, decreasing = TRUE, digits = 3, keep.zeros = TRUE),
"5.00e-06*x^4 + 4.00e-06*x^3 + 3.00e-06*x^2 + 2.00e-06*x + 1.00e-06")
expect_equal(poly2character(x = (1:5) * 1e+3, decreasing = TRUE, digits = 3, keep.zeros = TRUE),
"5.00e+03*x^4 + 4.00e+03*x^3 + 3.00e+03*x^2 + 2.00e+03*x + 1.000e+03")
"5.00e+03*x^4 + 4.00e+03*x^3 + 3.00e+03*x^2 + 2.00e+03*x + 1.00e+03")
expect_warning(poly2character(x = NA))
expect_true(is.na(suppressWarnings(poly2character(x = NA))))
expect_equal(poly2character(x = NULL), character(0))
Expand Down

0 comments on commit f112f8f

Please sign in to comment.