[R] Singular design matrix in rq

William Dunlap wdunlap at tibco.com
Tue Apr 16 23:40:47 CEST 2013


Have you looked at the result of
  bs(raw_data[,i], df=15)
?  If there are not many unique values in the input there
will be a lot of NaN's in the output (because there are
repeated knots) and those NaN's will cause rq() to give
that message.

E.g.,
> d <- data.frame(y=sin(1:100), x4=rep(1:4,each=25), x50=rep(1:50,each=2))
> rq(data=d, y ~ bs(x4, df=15), tau=.8) # using x50 "works"
Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
> with(d, bs(x4, df=15))
       1 2 3 4 5 6 7 8 9 10 11  12  13  14  15
  [1,] 0 0 1 0 0 0 0 0 0  0  0   0   0   0   0
  [2,] 0 0 1 0 0 0 0 0 0  0  0   0   0   0   0
  [3,] 0 0 1 0 0 0 0 0 0  0  0   0   0   0   0
  ...
[98,] 0 0 0 0 0 0 0 0 0  0  0 NaN NaN NaN NaN
 [99,] 0 0 0 0 0 0 0 0 0  0  0 NaN NaN NaN NaN
[100,] 0 0 0 0 0 0 0 0 0  0  0 NaN NaN NaN NaN
attr(,"degree")
[1] 3
attr(,"knots")
7.692308% 15.38462% 23.07692% 30.76923% 38.46154% 
        1         1         1         2         2 
46.15385% 53.84615% 61.53846% 69.23077% 76.92308% 
        2         3         3         3         4 
84.61538% 92.30769% 
        4         4 
attr(,"Boundary.knots")
[1] 1 4
attr(,"intercept")
[1] FALSE
attr(,"class")
[1] "bs"     "basis"  "matrix"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Jonathan Greenberg
> Sent: Tuesday, April 16, 2013 12:58 PM
> To: r-help; Roger Koenker
> Subject: [R] Singular design matrix in rq
> 
> Quantreggers:
> 
> I'm trying to run rq() on a dataset I posted at:
> https://docs.google.com/file/d/0B8Kij67bij_ASUpfcmJ4LTFEUUk/edit?usp=sharing
> (it's a 1500kb csv file named "singular.csv") and am getting the following
> error:
> 
> mydata <- read.csv("singular.csv")
> fit_spl <- rq(raw_data[,1] ~ bs(raw_data[,i],df=15),tau=1)
> > Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
> 
> Any ideas what might be causing this or, more importantly, suggestions for
> how to solve this?  I'm just trying to fit a smoothed hull to the top of
> the data cloud (hence the large df).
> 
> Thanks!
> 
> --jonathan
> 
> 
> --
> Jonathan A. Greenberg, PhD
> Assistant Professor
> Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
> Department of Geography and Geographic Information Science
> University of Illinois at Urbana-Champaign
> 607 South Mathews Avenue, MC 150
> Urbana, IL 61801
> Phone: 217-300-1924
> http://www.geog.illinois.edu/~jgrn/
> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list