Dear Roger,
The problem is this. qss() looks like this:
if (is.matrix(x)) {
[...]
}
if (is.vector(x)) {
[...]
}
qss
Now let's check these if() statements:
is.vector(B$x) # TRUE
is.vector(D$x) # FALSE
is.matrix(B$x) # FALSE
is.matrix(D$x) # FALSE
is.vector(D$x) being FALSE may be surprising, but see ?is.vector:
"is.vector returns TRUE if x is a vector of the specified mode having no
attributes other than names. It returns FALSE otherwise." And as D$x shows,
this vector has additional attributes.
So, with 'D', qss() returns the qss function (c.f., qss(B$x) and
qss(D$x)) which makes no sense. So, the internal logic in qss() needs to be
fixed.
>In accordance with the usual R-help etiquette I first tried to contact the
>maintainer of the haven package, i.e. RStudio, which elicited the response:
"since
>the error is occurring outside RStudio we?re not responsible, so try Stack
>Overflow". This is pretty much what I would have expected from the
capitalist
>running dogs they are. Admittedly, the error is probably due to some
unforeseen
This kind of bashing is really silly. Can you tell us again how much you paid
for the use of the haven package?
Best,
Wolfgang
>-----Original Message-----
>From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Koenker,
Roger W
>Sent: Saturday, 10 April, 2021 11:26
>To: r-help
>Subject: [R] Stata/Rstudio evil attributes
>
>As shown in the reproducible example below, I used the RStudio function
haven() to
>read a Stata .dta file, and then tried to do some fitting with the resulting
>data.frame. This produced an error from my fitting function rqss() in the
package
>quantreg. After a bit of frustrated cursing, I converted the data.frame, D,
to a
>matrix A, and thence back to a data.frame B, and tried again, which worked
as
>expected. The conversion removed the attributes of D. My question is: why
were
>the attributes inhibiting the fitting?
>
>In accordance with the usual R-help etiquette I first tried to contact the
>maintainer of the haven package, i.e. RStudio, which elicited the response:
"since
>the error is occurring outside RStudio we?re not responsible, so try Stack
>Overflow". This is pretty much what I would have expected from the
capitalist
>running dogs they are. Admittedly, the error is probably due to some
unforeseen
>infelicity in my rqss() coding, but it does seem odd that attributes could
have
>such a drastic effect. I would be most grateful for any insight the R
commune
>might offer.
>
>#require(haven) # for reading dta file
>#Ddta <- read_dta(?foo.dta")
>#D <- with(Ddta, data.frame(y = access_merg, x = meannets_allhh, z =
meanhh))
>#save(D, file = "D.Rda")
>con <-
url("http://www.econ.uiuc.edu/~roger/research/data/D.Rda")
>load(con)
>
># If I purge the Stata attributes in D:
>A <- as.matrix(D)
>B <- as.data.frame(A)
>
># This works:
>with(D,plot(x, y, cex = .5, col = "grey"))
>taus <- 1:4/5
>require(quantreg)
>for(i in 1:length(taus)){
> f <- rqss(y ~ qss(x, constraint = "I", lambda = 1), tau =
taus[i], data = B)
> plot(f, add = TRUE, col = i)
>}
># However, the same code with data = D, does not. Why?