{"action":"created","comment":{"url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/comments/156711024","pull_request_review_id":83233352,"id":156711024,"diff_hunk":"@@ -0,0 +1,502 @@\n+// [[Rcpp::depends(RcppArmadillo)]]\n+// [[Rcpp::depends(RcppEigen)]]\n+// [[Rcpp::plugins(cpp11)]]\n+\n+// These functions implement\n+// Using Heteroscedasticity Consistent Standard Errors in the Linear Regression Model\n+// J. Scott Long and Laurie H. Ervin\n+#define ARMA_64BIT_WORD 1\n+#include <RcppArmadillo.h>\n+#include <RcppEigen.h>\n+#include <Rcpp.h>\n+using namespace Rcpp;\n+\n+// Much of what follows is modified from RcppEigen Vignette by Douglas Bates and Dirk Eddelbuettel\n+// https://cran.r-project.org/web/packages/RcppEigen/vignettes/RcppEigen-Introduction.pdf\n+// [[Rcpp::export]]\n+Eigen::MatrixXd AtA(const Eigen::MatrixXd& A) {\n+  int n(A.cols());\n+  return Eigen::MatrixXd(n,n).setZero().selfadjointView<Eigen::Lower>()\n+                             .rankUpdate(A.adjoint());\n+}\n+\n+//' @export\n+// [[Rcpp::export]]\n+Eigen::MatrixXd mult_diag(const Eigen::MatrixXd& x, const Eigen::ArrayXd& d) {\n+\n+  Eigen::MatrixXd out(x.rows(), x.cols());\n+  for (unsigned j = 0; j < x.cols(); ++j) {\n+    out.col(j) = x.col(j) * d(j);\n+  }\n+\n+  return out;\n+}\n+\n+//' @export\n+// [[Rcpp::export]]\n+Eigen::VectorXd extract_vec(const Eigen::VectorXd& full, const Eigen::VectorXi& ind)\n+{\n+  int num_indices = ind.sum();\n+  Eigen::VectorXd target(num_indices);\n+  int j = 0;\n+  for (int i = 0; i < full.size(); i++)\n+  {\n+    if (ind(i) == 1) {\n+      target(j) = full(i);\n+      j++;\n+    }\n+  }\n+  return target;\n+}\n+\n+//' @export\n+// [[Rcpp::export]]\n+Eigen::MatrixXd extract_mat_rows(const Eigen::MatrixXd& full, const Eigen::VectorXi& ind)\n+{\n+  int num_indices = ind.sum();\n+  Eigen::MatrixXd target(num_indices, full.cols());\n+  int j = 0;\n+  for (int i = 0; i < full.rows(); i++)\n+  {\n+    if (ind(i) == 1) {\n+      target.row(j) = full.row(i);\n+      j++;\n+    }\n+  }\n+  return target;\n+}\n+\n+// extract_mat(const Eigen::DenseBase<Eigen::Matrix>& full, const Eigen::DenseBase<T>& ind)\n+// {\n+//   int num_indices = ind.innerSize();\n+//   target_t target(num_indices);\n+//   for (int i = 0; i < num_indices; i++)\n+//   {\n+//     target[i] = full[ind[i]];\n+//   }\n+//   return target;\n+// }\n+\n+//' @export\n+// [[Rcpp::export]]\n+List lm_ei_test(Eigen::Map<Eigen::MatrixXd>& Xfull,\n+                const Eigen::Map<Eigen::VectorXd>& y,\n+                const Rcpp::Nullable<Rcpp::NumericMatrix> & Xunweighted,\n+                const Rcpp::Nullable<Rcpp::NumericVector> & weight,\n+                const double & weight_mean,\n+                const Rcpp::Nullable<Rcpp::IntegerVector> & cluster,\n+                const unsigned & J,\n+                const bool & ci,\n+                const String type,\n+                const std::vector<bool> & which_covs,\n+                const bool& chol,\n+                const bool& trychol) {\n+\n+  const int n(Xfull.rows()), p(Xfull.cols());\n+  int r = p;\n+  Eigen::MatrixXd Xfullt(Xfull.transpose());\n+  Eigen::MatrixXd XtX_inv, R_inv, Vcov_hat;\n+  Eigen::VectorXd beta_out(Eigen::VectorXd::Constant(p, ::NA_REAL));\n+\n+  bool full_rank = true;\n+\n+  // Many of the lines below are inspired by the fastLm function from RcppEigen\n+  // https://cran.r-project.org/web/packages/RcppEigen/vignettes/RcppEigen-Introduction.pdf\n+  if (chol) {\n+    const Eigen::LLT<Eigen::MatrixXd> llt(Xfullt*Xfull);\n+    beta_out = llt.solve(Xfull.adjoint() * y);\n+    R_inv = llt.matrixL().solve(Eigen::MatrixXd::Identity(p, p));\n+    XtX_inv = R_inv.transpose() * R_inv;\n+  } else {\n+    try {\n+      if (trychol) {\n+        const Eigen::LLT<Eigen::MatrixXd> llt(Xfullt*Xfull);\n+\n+        // Catch case where Xfull is rank-deficient\n+        if(llt.info() == Eigen::NumericalIssue) {\n+          full_rank = false;\n+          throw std::runtime_error(\"Possibly non semi-positive definite matrix!\");","path":"src/lm_speed.cpp","position":118,"original_position":118,"commit_id":"8de9ffe968719b736c56df6dd96c8fc050f22193","original_commit_id":"8de9ffe968719b736c56df6dd96c8fc050f22193","user":{"login":"lukesonnet","id":5298599,"avatar_url":"https://avatars0.githubusercontent.com/u/5298599?v=4","gravatar_id":"","url":"https://api.github.com/users/lukesonnet","html_url":"https://github.com/lukesonnet","followers_url":"https://api.github.com/users/lukesonnet/followers","following_url":"https://api.github.com/users/lukesonnet/following{/other_user}","gists_url":"https://api.github.com/users/lukesonnet/gists{/gist_id}","starred_url":"https://api.github.com/users/lukesonnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukesonnet/subscriptions","organizations_url":"https://api.github.com/users/lukesonnet/orgs","repos_url":"https://api.github.com/users/lukesonnet/repos","events_url":"https://api.github.com/users/lukesonnet/events{/privacy}","received_events_url":"https://api.github.com/users/lukesonnet/received_events","type":"User","site_admin":false},"body":"Force an exception if there is a \"NumericalIssue\" with the eigen decomposition.","created_at":"2017-12-13T16:31:51Z","updated_at":"2017-12-13T16:31:51Z","html_url":"https://github.com/DeclareDesign/estimatr/pull/65#discussion_r156711024","pull_request_url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/comments/156711024"},"html":{"href":"https://github.com/DeclareDesign/estimatr/pull/65#discussion_r156711024"},"pull_request":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65"}}},"pull_request":{"url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65","id":158140455,"html_url":"https://github.com/DeclareDesign/estimatr/pull/65","diff_url":"https://github.com/DeclareDesign/estimatr/pull/65.diff","patch_url":"https://github.com/DeclareDesign/estimatr/pull/65.patch","issue_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues/65","number":65,"state":"open","locked":false,"title":"Migrate to Eigen; allow rank-deficient X matrices","user":{"login":"lukesonnet","id":5298599,"avatar_url":"https://avatars0.githubusercontent.com/u/5298599?v=4","gravatar_id":"","url":"https://api.github.com/users/lukesonnet","html_url":"https://github.com/lukesonnet","followers_url":"https://api.github.com/users/lukesonnet/followers","following_url":"https://api.github.com/users/lukesonnet/following{/other_user}","gists_url":"https://api.github.com/users/lukesonnet/gists{/gist_id}","starred_url":"https://api.github.com/users/lukesonnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukesonnet/subscriptions","organizations_url":"https://api.github.com/users/lukesonnet/orgs","repos_url":"https://api.github.com/users/lukesonnet/repos","events_url":"https://api.github.com/users/lukesonnet/events{/privacy}","received_events_url":"https://api.github.com/users/lukesonnet/received_events","type":"User","site_admin":false},"body":"Placeholder, will be filled out when merge is actually ready. Currently PR exists for review purposes.\r\n\r\nPlease do not merge yet!","created_at":"2017-12-13T16:26:39Z","updated_at":"2017-12-13T16:31:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e345fdf57e25d9a990b7ab6868c664677284286c","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65/commits","review_comments_url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65/comments","review_comment_url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues/65/comments","statuses_url":"https://api.github.com/repos/DeclareDesign/estimatr/statuses/8de9ffe968719b736c56df6dd96c8fc050f22193","head":{"label":"DeclareDesign:lukesonnet/lm_speed","ref":"lukesonnet/lm_speed","sha":"8de9ffe968719b736c56df6dd96c8fc050f22193","user":{"login":"DeclareDesign","id":15285286,"avatar_url":"https://avatars0.githubusercontent.com/u/15285286?v=4","gravatar_id":"","url":"https://api.github.com/users/DeclareDesign","html_url":"https://github.com/DeclareDesign","followers_url":"https://api.github.com/users/DeclareDesign/followers","following_url":"https://api.github.com/users/DeclareDesign/following{/other_user}","gists_url":"https://api.github.com/users/DeclareDesign/gists{/gist_id}","starred_url":"https://api.github.com/users/DeclareDesign/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DeclareDesign/subscriptions","organizations_url":"https://api.github.com/users/DeclareDesign/orgs","repos_url":"https://api.github.com/users/DeclareDesign/repos","events_url":"https://api.github.com/users/DeclareDesign/events{/privacy}","received_events_url":"https://api.github.com/users/DeclareDesign/received_events","type":"Organization","site_admin":false},"repo":{"id":86030420,"name":"estimatr","full_name":"DeclareDesign/estimatr","owner":{"login":"DeclareDesign","id":15285286,"avatar_url":"https://avatars0.githubusercontent.com/u/15285286?v=4","gravatar_id":"","url":"https://api.github.com/users/DeclareDesign","html_url":"https://github.com/DeclareDesign","followers_url":"https://api.github.com/users/DeclareDesign/followers","following_url":"https://api.github.com/users/DeclareDesign/following{/other_user}","gists_url":"https://api.github.com/users/DeclareDesign/gists{/gist_id}","starred_url":"https://api.github.com/users/DeclareDesign/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DeclareDesign/subscriptions","organizations_url":"https://api.github.com/users/DeclareDesign/orgs","repos_url":"https://api.github.com/users/DeclareDesign/repos","events_url":"https://api.github.com/users/DeclareDesign/events{/privacy}","received_events_url":"https://api.github.com/users/DeclareDesign/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DeclareDesign/estimatr","description":"Fast estimators for social scientists","fork":false,"url":"https://api.github.com/repos/DeclareDesign/estimatr","forks_url":"https://api.github.com/repos/DeclareDesign/estimatr/forks","keys_url":"https://api.github.com/repos/DeclareDesign/estimatr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DeclareDesign/estimatr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DeclareDesign/estimatr/teams","hooks_url":"https://api.github.com/repos/DeclareDesign/estimatr/hooks","issue_events_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues/events{/number}","events_url":"https://api.github.com/repos/DeclareDesign/estimatr/events","assignees_url":"https://api.github.com/repos/DeclareDesign/estimatr/assignees{/user}","branches_url":"https://api.github.com/repos/DeclareDesign/estimatr/branches{/branch}","tags_url":"https://api.github.com/repos/DeclareDesign/estimatr/tags","blobs_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/refs{/sha}","trees_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DeclareDesign/estimatr/statuses/{sha}","languages_url":"https://api.github.com/repos/DeclareDesign/estimatr/languages","stargazers_url":"https://api.github.com/repos/DeclareDesign/estimatr/stargazers","contributors_url":"https://api.github.com/repos/DeclareDesign/estimatr/contributors","subscribers_url":"https://api.github.com/repos/DeclareDesign/estimatr/subscribers","subscription_url":"https://api.github.com/repos/DeclareDesign/estimatr/subscription","commits_url":"https://api.github.com/repos/DeclareDesign/estimatr/commits{/sha}","git_commits_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/commits{/sha}","comments_url":"https://api.github.com/repos/DeclareDesign/estimatr/comments{/number}","issue_comment_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues/comments{/number}","contents_url":"https://api.github.com/repos/DeclareDesign/estimatr/contents/{+path}","compare_url":"https://api.github.com/repos/DeclareDesign/estimatr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DeclareDesign/estimatr/merges","archive_url":"https://api.github.com/repos/DeclareDesign/estimatr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DeclareDesign/estimatr/downloads","issues_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues{/number}","pulls_url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls{/number}","milestones_url":"https://api.github.com/repos/DeclareDesign/estimatr/milestones{/number}","notifications_url":"https://api.github.com/repos/DeclareDesign/estimatr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DeclareDesign/estimatr/labels{/name}","releases_url":"https://api.github.com/repos/DeclareDesign/estimatr/releases{/id}","deployments_url":"https://api.github.com/repos/DeclareDesign/estimatr/deployments","created_at":"2017-03-24T05:25:49Z","updated_at":"2017-11-30T01:56:10Z","pushed_at":"2017-12-13T16:29:47Z","git_url":"git://github.com/DeclareDesign/estimatr.git","ssh_url":"git@github.com:DeclareDesign/estimatr.git","clone_url":"https://github.com/DeclareDesign/estimatr.git","svn_url":"https://github.com/DeclareDesign/estimatr","homepage":"http://estimatr.declaredesign.org","size":1966,"stargazers_count":6,"watchers_count":6,"language":"R","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":18,"watchers":6,"default_branch":"master"}},"base":{"label":"DeclareDesign:master","ref":"master","sha":"afa836b478b94415f134565fdca6f5446fd40e20","user":{"login":"DeclareDesign","id":15285286,"avatar_url":"https://avatars0.githubusercontent.com/u/15285286?v=4","gravatar_id":"","url":"https://api.github.com/users/DeclareDesign","html_url":"https://github.com/DeclareDesign","followers_url":"https://api.github.com/users/DeclareDesign/followers","following_url":"https://api.github.com/users/DeclareDesign/following{/other_user}","gists_url":"https://api.github.com/users/DeclareDesign/gists{/gist_id}","starred_url":"https://api.github.com/users/DeclareDesign/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DeclareDesign/subscriptions","organizations_url":"https://api.github.com/users/DeclareDesign/orgs","repos_url":"https://api.github.com/users/DeclareDesign/repos","events_url":"https://api.github.com/users/DeclareDesign/events{/privacy}","received_events_url":"https://api.github.com/users/DeclareDesign/received_events","type":"Organization","site_admin":false},"repo":{"id":86030420,"name":"estimatr","full_name":"DeclareDesign/estimatr","owner":{"login":"DeclareDesign","id":15285286,"avatar_url":"https://avatars0.githubusercontent.com/u/15285286?v=4","gravatar_id":"","url":"https://api.github.com/users/DeclareDesign","html_url":"https://github.com/DeclareDesign","followers_url":"https://api.github.com/users/DeclareDesign/followers","following_url":"https://api.github.com/users/DeclareDesign/following{/other_user}","gists_url":"https://api.github.com/users/DeclareDesign/gists{/gist_id}","starred_url":"https://api.github.com/users/DeclareDesign/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DeclareDesign/subscriptions","organizations_url":"https://api.github.com/users/DeclareDesign/orgs","repos_url":"https://api.github.com/users/DeclareDesign/repos","events_url":"https://api.github.com/users/DeclareDesign/events{/privacy}","received_events_url":"https://api.github.com/users/DeclareDesign/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DeclareDesign/estimatr","description":"Fast estimators for social scientists","fork":false,"url":"https://api.github.com/repos/DeclareDesign/estimatr","forks_url":"https://api.github.com/repos/DeclareDesign/estimatr/forks","keys_url":"https://api.github.com/repos/DeclareDesign/estimatr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DeclareDesign/estimatr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DeclareDesign/estimatr/teams","hooks_url":"https://api.github.com/repos/DeclareDesign/estimatr/hooks","issue_events_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues/events{/number}","events_url":"https://api.github.com/repos/DeclareDesign/estimatr/events","assignees_url":"https://api.github.com/repos/DeclareDesign/estimatr/assignees{/user}","branches_url":"https://api.github.com/repos/DeclareDesign/estimatr/branches{/branch}","tags_url":"https://api.github.com/repos/DeclareDesign/estimatr/tags","blobs_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/refs{/sha}","trees_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DeclareDesign/estimatr/statuses/{sha}","languages_url":"https://api.github.com/repos/DeclareDesign/estimatr/languages","stargazers_url":"https://api.github.com/repos/DeclareDesign/estimatr/stargazers","contributors_url":"https://api.github.com/repos/DeclareDesign/estimatr/contributors","subscribers_url":"https://api.github.com/repos/DeclareDesign/estimatr/subscribers","subscription_url":"https://api.github.com/repos/DeclareDesign/estimatr/subscription","commits_url":"https://api.github.com/repos/DeclareDesign/estimatr/commits{/sha}","git_commits_url":"https://api.github.com/repos/DeclareDesign/estimatr/git/commits{/sha}","comments_url":"https://api.github.com/repos/DeclareDesign/estimatr/comments{/number}","issue_comment_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues/comments{/number}","contents_url":"https://api.github.com/repos/DeclareDesign/estimatr/contents/{+path}","compare_url":"https://api.github.com/repos/DeclareDesign/estimatr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DeclareDesign/estimatr/merges","archive_url":"https://api.github.com/repos/DeclareDesign/estimatr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DeclareDesign/estimatr/downloads","issues_url":"https://api.github.com/repos/DeclareDesign/estimatr/issues{/number}","pulls_url":"https://api.github.com/repos/DeclareDesign/estimatr/pulls{/number}","milestones_url":"https://api.github.com/repos/DeclareDesign/estimatr/milestones{/number}","notifications_url":"https://api.github.com/repos/DeclareDesign/estimatr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DeclareDesign/estimatr/labels{/name}","releases_url":"https://api.github.com/repos/DeclareDesign/estimatr/releases{/id}","deployments_url":"https://api.github.com/repos/DeclareDesign/estimatr/deployments","created_at":"2017-03-24T05:25:49Z","updated_at":"2017-11-30T01:56:10Z","pushed_at":"2017-12-13T16:29:47Z","git_url":"git://github.com/DeclareDesign/estimatr.git","ssh_url":"git@github.com:DeclareDesign/estimatr.git","clone_url":"https://github.com/DeclareDesign/estimatr.git","svn_url":"https://github.com/DeclareDesign/estimatr","homepage":"http://estimatr.declaredesign.org","size":1966,"stargazers_count":6,"watchers_count":6,"language":"R","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":18,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65"},"html":{"href":"https://github.com/DeclareDesign/estimatr/pull/65"},"issue":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/issues/65"},"comments":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/issues/65/comments"},"review_comments":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65/comments"},"review_comment":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/pulls/65/commits"},"statuses":{"href":"https://api.github.com/repos/DeclareDesign/estimatr/statuses/8de9ffe968719b736c56df6dd96c8fc050f22193"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"lukesonnet"}}