X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2FR%2Futils.R;h=6ac9beca5911aa52cef7ab9ac465d061d3ba0b04;hp=6d1c36161204b25db17c2c237bcfb77b62ba3556;hb=4263503b0fbe45a6fa5b353c8405e30557b3dd70;hpb=e92d9d9dad0780d1a7eec27220c31254c20ab60d diff --git a/pkg/R/utils.R b/pkg/R/utils.R index 6d1c361..6ac9bec 100644 --- a/pkg/R/utils.R +++ b/pkg/R/utils.R @@ -74,6 +74,23 @@ normalize = function(X) computeMoments = function(X, Y) list( colMeans(Y * X), .Moments_M2(X,Y), .Moments_M3(X,Y) ) +# Computes the Omega matrix for generalized least square method +# +# @param X matrix of covariates (of size n*d) +# @param Y vector of responses (of size n) +# @param theta list with p, beta, b +# +# @return Matrix of size dimxdim where dim=d+d^2+d^3 +# +.Moments_M3 = function(X, Y) +{ + n = nrow(X) + d = ncol(X) + M3 = array(0,dim=c(d,d,d)) + array( .C("Moments_M3", X=as.double(X), Y=as.double(Y), pn=as.integer(n), + pd=as.integer(d), M3=as.double(M3), PACKAGE="morpheus")$M3, dim=c(d,d,d) ) +} + # Find the optimal assignment (permutation) between two sets (minimize cost) # # @param distances The distances matrix, in columns (distances[i,j] is distance between i