[R] Matrix:::qr.qy and signature(qr = sparseQR, y = dgCMatrix)

2011-08-23 Thread Felix Lamp
 sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] Matrix_0.999375-50 lattice_0.19-30   

loaded via a namespace (and not attached):
[1] grid_2.13.1  tools_2.13.1

Dear R-help,

I am using the Matrix (0.999375-50) and MatrixModels (0.2-1) packages to 
estimate regressions with 14,791 fixed effects. I use the function 
sparse.model.matrix() to partial out the fixed effects and then use lm() and an 
adjustment to the standard errors to study the four regressors that I am 
interested in.

I want to calculate standardized residuals and need the diagonal elements of 
the hat matrix. I tried to adjust function hat() in the stats package for use 
with sparse matrices. But the method qr.qy does not seem to have a function 
available for the following signature: signature(qr = sparseQR, y = 
dgCMatrix) - although it indicates that it understands this signature.

Following is a minimal example (in my application dd2 is too large for my 
memory):

library(Matrix)


data(KNex); 
mm - KNex$mm
mmQR - qr(mm)
dim(mmQR) # 1850  712



class(mmQR) # [1] sparseQR;attr(,package);Matrix

dd1 - sparseMatrix(1:ncol(mm),1:ncol(mm), x = 1, dims = c(nrow(mm),ncol(mm)))

class(dd1) # dgCMatrix;attr(,package);Matrix

dd2 - diag(1,ncol = ncol(mm) , nrow = nrow(mm))

class(dd2) #matrix

showMethods(qr.qy)
#Function: qr.qy (package base)
#qr=ANY, y=ANY
#qr=sparseQR, y=dgCMatrix
#(inherited from: qr=ANY, y=ANY)
#qr=sparseQR, y=dgeMatrix
#qr=sparseQR, y=matrix
#qr=sparseQR, y=numeric


dhat1 - rowSums(qr.qy(qr = mmQR, y = dd1)^2) # Error in rowSums(qr.qy(qr = 
mmQR, y = dd1)^2) : 
  # error in evaluating the argument 'x' in selecting a method for function 
'rowSums': 
  # Error in qr.qy(qr = mmQR, y = dd1) : argument is not a QR decomposition


dhat2 - rowSums(qr.qy(qr = mmQR, y = dd2)^2) # Works fine


I would be grateful for pointers how to add a function for Matrix:::qr.qy and 
signature(qr = sparseQR, y = dgCMatrix). What low level functions do I have 
to call?
I would also be grateful for any suggestions for finding diagonal values of the 
hat matrix in regression problems with large and sparse design matrices.


Best,

Felix Lamp
(Erasmus University Rotterdam, School of Economics)





[[alternative HTML version deleted]]

__
R-help@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.


[R] fGarch and is.na()

2008-12-02 Thread Felix Lamp
Hello,

after loading package fGarch the function is.na.data.frame() is behaving 
different:

 sessionInfo()
R version 2.8.0 (2008-10-20) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 
 
 dfr  - data.frame(matrix(0,nrow = 1 , ncol = 1000))
 dfr2 - is.na(dfr)
 
 require(fGarch)
Loading required package: fGarch
Loading required package: timeDate
Loading required package: timeSeries
Loading required package: fBasics
Loading required package: MASS
 
 dfr2 - is.na(dfr)
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
 

I wonder whether this is intended.

Best,

Felix


Tinbergen Institute
P.O. Box 1738
3000 DR Rotterdam

__
R-help@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.


[R] Weights argument in loess (stats)

2007-11-14 Thread Felix Lamp
Hello,

I have a question concerning the weights argument of the loess
function in the stats package.

Do the weights correspond to multiplying the local regression
equation by the weights or by the square root of the weights (like in lm).

In http://www.netlib.org/a/cloess.pdf; page 7 it appears that the former
is true.
A look at the source code loess.f lets me conclude that the latter is   true.

Since I do not know Fortran, I would be really delighted if someone could
clarify this.

Best,

Felix

__
R-help@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.