[Rcpp-devel] Correlation in ArmadilloRcpp with missing values (nan)
mateusz.kaduk at gmail.com
mateusz.kaduk at gmail.com
Tue Oct 9 20:25:03 CEST 2012
The problem is that I want to calculate regression etc. with these
shorter vectors.
So yes what I do first is I am calculating vector with zero wherever
the missing will occur, simply by pairwise multiplication.
colvec indX = a(span::all,i);
colvec indY = a(span::all,j)
colvec indZ = a(span::all,k);
colvec ind = indX % indY % indZ;
uvec rowind = conv_to<uvec>::from(ind);
the a matrix is is the arma::mat object with ones where there is
value, and zeros where there are missings (nan).
ind is the colvec with pairwise product, and for any operation and
regression further I want to select with rowind.
But compiler complains on
colvec colX = x.submat(rowind,i);
colvec colY = x.submat(rowind,j);
I think I can use just cor(..) if I remove the common row, in all
vectors I use for i and j columns of the matrix.
Let me think of example.
On 9 October 2012 20:18, Douglas Bates <bates at stat.wisc.edu> wrote:
>
> On Tue, Oct 9, 2012 at 1:06 PM, mateusz.kaduk at gmail.com
> <mateusz.kaduk at gmail.com> wrote:
> > Maybe I am not good in coding, but even though I managed to make uvec with
> > ones and zeros, I cannot use it to select rows in given column, compiler
> > complains
> > error: no matching function for call to
> > ‘arma::Mat<double>::submat(arma::uvec&, int&)’
>
> Basically your problem comes down to looking at each pair of columns
> and determining the joint missingness pattern. You can try to force
> the calculation into arma but I think you are better off just writing
> the code in loops. To be careful you should calculate the means of
> each column on the pairwise non-missing values as in the enclosed
> function.
>
> > On 9 October 2012 19:55, Dirk Eddelbuettel <edd at debian.org> wrote:
> >>
> >>
> >> On 9 October 2012 at 19:07, mateusz.kaduk at gmail.com wrote:
> >> | Can you provide an example how to convert Armadillo colvec to uvec
> >> vector which
> >> | I assume works as selector for rows?
> >>
> >> You may need to loop (or use STL iterators) to fill the uvec position by
> >> position. Then use the subset, and proceed with your correlation
> >> calculation. I don't think there is a shortcut.
> >>
> >> Dirk
> >>
> >> --
> >> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> >
> >
More information about the Rcpp-devel
mailing list