Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add as.matrix to sim_TS #142

Merged
merged 2 commits into from
Dec 23, 2019
Merged

Add as.matrix to sim_TS #142

merged 2 commits into from
Dec 23, 2019

Conversation

diazrenata
Copy link
Member

If X only has one column, X[in1,] is a vector and the matrix multiplication fails. Adding the as.matrix seems to fix it.

If X only has one column, X[in1,] is a vector and the matrix multiplication fails.
@codecov-io
Copy link

codecov-io commented Aug 12, 2019

Codecov Report

Merging #142 into sim_edits will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           sim_edits     #142   +/-   ##
==========================================
  Coverage      97.71%   97.71%           
==========================================
  Files             11       11           
  Lines           1223     1223           
==========================================
  Hits            1195     1195           
  Misses            28       28
Impacted Files Coverage Δ
R/simulate.R 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4f1a84...b67292f. Read the comment docs.

Using only as.matrix() fails if there is only 1 year in a segment and there are multiple covariates. In that case, as.matrix(X[in1, ]) returns a matrix of n_covariates rows x 1 column, instead of a matrix of 1 row and n_covariates columns. This edit should fix that by forcing it into a matrix of the correct number of rows.
@juniperlsimonis juniperlsimonis merged commit e85f7ce into sim_edits Dec 23, 2019
@gavinsimpson
Copy link

A simpler fix to avoid this issue entirely would be to stop R dropping the empty dimension when X is subset. For example:

X_Eta <- X[in1, , drop = FALSE] %*% Eta[in2,]`

If Eta is also a matrix object then it to probably should be protected from dropping empty dimensions. I'm not sure if that is possible given other code, but to be defensive one would use

X_Eta <- X[in1, , drop = FALSE] %*% Eta[in2, , drop = FALSE]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants