harrelfe / Hmisc

Harrell Miscellaneous
Other
208 stars 81 forks source link

largest.empty does not return largest empty area #136

Open chrisdane opened 3 years ago

chrisdane commented 3 years ago

Hi

In a specific case Hmisc::largest.empty(x, y, method="area") does not return the largest empty rectangle (code example Hmisc_largest.empty_example.txt):

Hmisc_largest empty_example

The area of Hmisc::largest.empty (blue) is 1078482. The area of my own 'by-eye' rectangle (red) is 1855670, i.e. much larger. Do I misunderstand something here? The important lines are

# x, y see attached .txt file
plot(x,y)
library(Hmisc)
tmp <- Hmisc::largest.empty(x=x, y=y, method="area")
rect(tmp$rect$x[1], tmp$rect$y[1], tmp$rect$x[2], tmp$rect$y[3], border="blue")
rect(par("usr")[1], -2600, par("usr")[2], -1200, border="red")
message("Hmisc blue area: ", tmp$area)
# Hmisc blue area: 1078482.91586984
message("own red area: ", diff(par("usr")[1:2])*diff(c(-2600, -1200)))
# own red area: 1855670.95159074

Thanks a lot for any help, Chris