fastglmm
Massively scalable generalized linear mixed models
Loading...
Searching...
No Matches
exportToR_fastlmm.h
Go to the documentation of this file.
1
2/***************************************************************
3 * @file exportToR_fastlmm.h
4 * @author Gabriel Hoffman
5 * @email gabriel.hoffman@mssm.edu
6 * @brief Export results to R as List
7 * Copyright (C) 2024 Gabriel Hoffman
8 **************************************************************/
9
10#ifndef _EXPORT_TO_R_FASTLMM_
11#define _EXPORT_TO_R_FASTLMM_
12
13#ifdef USE_R
14
15using namespace Rcpp;
16using namespace fastglmmLib;
17
18// Depends on Rcpp::List, so define outside of class
19const List toList(ModelFitLMM &res){
20
21 List lst = List::create(
22 Named("logLik") = res.logLik,
23 Named("coefficients") = res.coef,
24 Named("se") = res.se,
25 Named("vcov") = res.vcov,
26 Named("weights") = res.weights,
27 Named("delta") = res.delta,
28 Named("sigSq_g") = res.sigSq_g,
29 Named("sigSq_e") = res.sigSq_e,
30 Named("dispersion") = res.dispersion,
31 Named("ru") = res.ru,
32 Named("y") = res.y,
33 Named("iter") = res.iter,
34 Named("w.mean") = res.w_mean,
35 Named("s") = res.s,
36 Named("hessian.vc") = res.hessian_vc,
37 Named("A.sat") = res.A_sat,
38 Named("B.sat") = res.B_sat);
39
40 // Set U as either full or sparse matrix
41 if( res.isSet_U ) lst["U"] = res.U;
42 if( res.isSet_Usp ) lst["U"] = res.Usp;
43
44 // Set V as either full or sparse matrix
45 if( res.isSet_V ) lst["V"] = res.V;
46 if( res.isSet_Vsp ) lst["V"] = res.Vsp;
47
48 return lst;
49}
50
51template <typename T1, typename T2, typename T3>
52const List toList(fastlmm<T1, T2, T3> & fit){
53
54 ModelFitLMM res = fit.get_result( true );
55
56 return toList( res );
57}
58
59List toList( const vector<ModelFitLMM> &resList){
60 List L = List::create();
61
62 for(int i=0; i<resList.size(); i++){
63 ModelFitLMM res = resList.at(i);
64 L.push_back( toList( res ) );
65 }
66 return L;
67}
68
69
70
71// Depends on Rcpp::List, so define outside of class
72const List toList(ModelFitGLMM &res){
73
74 List lst = List::create(
75 Named("logLik") = res.logLik,
76 Named("coefficients") = res.coef,
77 Named("se") = res.se,
78 Named("vcov") = res.vcov,
79 Named("weights") = res.weights,
80 Named("delta") = res.delta,
81 Named("sigSq_g") = res.sigSq_g,
82 Named("sigSq_e") = res.sigSq_e,
83 Named("dispersion") = res.dispersion,
84 Named("ru") = res.ru,
85 Named("y") = res.y,
86 Named("family") = res.family,
87 Named("iter") = res.iter,
88 Named("w.mean") = res.w_mean,
89 Named("s") = res.s,
90 Named("hessian.vc") = res.hessian_vc,
91 Named("A.sat") = res.A_sat,
92 Named("B.sat") = res.B_sat);
93
94 // Set U as either full or sparse matrix
95 if( res.isSet_U ) lst["U"] = res.U;
96 if( res.isSet_Usp ) lst["U"] = res.Usp;
97
98 // Set V as either full or sparse matrix
99 if( res.isSet_V ) lst["V"] = res.V;
100 if( res.isSet_Vsp ) lst["V"] = res.Vsp;
101
102 return lst;
103}
104
105template <typename T1, typename T2, typename T3>
106const List toList(fastglmm<T1, T2, T3> & fit){
107
108 ModelFitGLMM res = fit.get_result();
109
110 return toList( res );
111}
112
113#endif
114#endif
Definition ModelFit.h:355
string family
Definition ModelFit.h:385
vec coef
Definition ModelFit.h:40
mat vcov
Definition ModelFit.h:45
vec se
Definition ModelFit.h:41
double dispersion
Definition ModelFit.h:42
Definition ModelFit.h:201
double w_mean
Definition ModelFit.h:208
double logLik
Definition ModelFit.h:204
vec ru
Definition ModelFit.h:205
sp_mat Vsp
Definition ModelFit.h:215
double sigSq_g
Definition ModelFit.h:206
mat A_sat
Definition ModelFit.h:219
mat hessian_vc
Definition ModelFit.h:219
vec s
Definition ModelFit.h:216
mat V
Definition ModelFit.h:214
vec y
Definition ModelFit.h:205
mat U
Definition ModelFit.h:214
bool isSet_U
Definition ModelFit.h:210
bool isSet_Vsp
Definition ModelFit.h:213
double sigSq_e
Definition ModelFit.h:206
mat B_sat
Definition ModelFit.h:219
double delta
Definition ModelFit.h:206
sp_mat Usp
Definition ModelFit.h:215
vec weights
Definition ModelFit.h:205
bool isSet_V
Definition ModelFit.h:212
int iter
Definition ModelFit.h:207
bool isSet_Usp
Definition ModelFit.h:211
Definition fastglmm_fit.h:37
ModelFitGLMM get_result()
Definition fastglmm_fit.h:295
Definition fastlmm_fit.h:35
ModelFitLMM get_result(const bool &returnUS=false)
Definition fastlmm_fit.h:531
Definition CleanData.h:17