gastonstat / plspm

R package plspm
62 stars 26 forks source link

matrix operations with blocks of 2 MVs in get_weights_nonmetric() #1

Open guilhemchalancon opened 10 years ago

guilhemchalancon commented 10 years ago

Dear Gaston, I run into a bug when specifying the scaling argument in plpsm() for models that contain formative blocks (mode B) with 2 manifest variables (MVs).

The reason for this is comes from get_weights_nonmetric(), which is called whenever scaling is specified (even if all MVs are specified to be numerical).

In this function, the computation of X* when mode B is used is given by:

X.star[, p] <- (1/Beta[p]) * (Z[, q] - (QQ[[q]][, -p] %*% Beta[-p]))

Where q refers to the LV, p to the MV.

The problem is that when block_sizes[q] == 2, then QQ[[q]][,-p] won't be a matrix object, but a numeric vector, which causes the %*% operation to fail.

The fix is very simple: QQ[[q]][ -p, drop = FALSE ] should be used in the definition of X.star[,p]

Best regards, G

guilhemchalancon commented 10 years ago

I forgot to mention that this is relevant for the development version of the package (30aaec0a44b5c8be7bc24ef48dcf8283ce6b80f2).