[R] Re gression between columns in matrix - with some/full NAs

From: rcoder <mpdotbook_at_gmail.com>
Date: Wed, 30 Jul 2008 11:01:19 -0700 (PDT)

Hi Anna,

Thanks for your reply and suggestions. I'm trying something different, based on regression this time, albeit giving similar problems. I want to regress a single column in a matrix with each other column in the same matrix, and o/p the intercept and slope coefficients to a results matrix.

The loop below works, even when I have columns with partial NAs, but exits with an error when a column with only NAs is encountered. So, the 'na.action=NULL' statement (see last line of code below) doesn't seem to work in this case, or perhaps I am applying it incorrectly. I would be very grateful for any pointers in the right direction:

>ResultMat<-matrix(NA, ncol=colnum, nrow=rownum) #creates an o/p

template matrix

#loop through each column in the source matrix:
>for (i in 1:5000)

	sel_col<-[col(SourceMat)==i]	#selecting the correct column in the matrix in
	SourceMat[,i]<-coef(lm(tt~sel_col), na.action=NULL)



rcoder wrote:
> Hi everyone,
> I'm having trouble applying the Cor() function to two matrices, both of
> which contain NAs. I am doing the following:
> a<-cor(m1, m2, use="complete.obs")
> ... and I get the following error message:
> Error in cor(m1, m2, use = "complete.obs") :
> no complete element pairs
> Does anyone know how I can apply a correlation, ignoring any NAs?
> Thanks,
> rcoder

View this message in context: http://www.nabble.com/correlation-between-matrices---both-with-some-NAs-tp18721853p18739148.html
Sent from the R help mailing list archive at Nabble.com.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 30 Jul 2008 - 18:45:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Jul 2008 - 19:32:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive