Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

glmm.h

Go to the documentation of this file.
00001 
00002 //****************************************************
00003 // GLMM class July 2000, University of Nebraska 2000 Stephen D. Kachman
00004 //****************************************************
00005 //  April, 1993, University of Illinois
00006 // Copyright (C) 1993, 1994 Tianlin Wang
00007 /* Copyright (C) 1994-2003 Matvec Development Team. 
00008 
00009   This program is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Library General Public
00011   License as published by the Free Software Foundation; either
00012   version 2 of the License, or (at your option) any later version.
00013   
00014   This program is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Library General Public License for more details.
00018     
00019   You should have received a copy of the GNU Library General Public
00020   License along with this library; if not, write to the Free
00021   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00022   MA 02111-1307, USA 
00023 */      
00024 
00025 
00026 #ifndef MATVEC_GLMM__H
00027 #define MATVEC_GLMM__H
00028 
00029 namespace matvec {
00030 class Observe {
00031 public: 
00032   void **param;
00033   int numtrait,rec,pev_current;
00034   int need_data;
00035   std::string pattern;
00036   Vector<double> residual;
00037   Vector<double> estimate;
00038   doubleMatrix pev;
00039   doubleMatrix rve;
00040   Vector<double> rpy;
00041   doubleMatrix W,Adj_Cov; // {sum_j (y_{ij}-u_{ij})_j {\partial R^{-1}_iH_i\over \partial \eta_k}
00042   Vector<double> q; //q is the q in \ell = y'q+....
00043   Vector<double> est_null; // Estimate under HO
00044   double weight;
00045   double like_val;
00046   Vector<double> y;
00047   doubleMatrix Resid_Var;
00048   doubleMatrix H;
00049   doubleMatrix Hinv;
00050   int nvc;
00051   doubleMatrix *Resid_Sin_Mat;
00052   doubleMatrix *resid_var;
00053   Vector<double> *varcomp;
00054   Data *data;
00055   Observe() {pattern="";nvc=0;Resid_Sin_Mat=0;varcomp=0;
00056   pev_current=0;like_val=0;data=0;param=0;};
00057   ~Observe() {
00058         if(Resid_Sin_Mat) delete [] Resid_Sin_Mat;Resid_Sin_Mat=0;
00059     };
00060   int display(void) const {std::cout<<"\tan object of Observe\n";return 1;};
00061 } ;
00062 
00063 
00064 
00065 
00066 
00067 
00068 class GLMM : public Model{
00069 public:
00070   virtual        double   contrast(const Vector<double>& Kp, const double m=0.0)
00071   ;
00072   virtual        double   contrast(const doubleMatrix& Kp, const Vector<double>& M)
00073   ;
00074   virtual        double   contrast(const doubleMatrix& Kp)
00075   ;
00076   virtual        double   contrast(const std::string &termname,const doubleMatrix& Kp,const Vector<double>& M)
00077   ;
00078 protected:
00079    virtual void     setup_ww(Vector<double>* rhs);
00080 
00081 public:
00082      int      equation(const std::string &modelspecs);
00083       virtual double   contrast(const double **kpme, const unsigned nr,
00084                         const unsigned nc,const double *M=0,
00085                         const int prt_flag=1,double **result=0);
00086 
00087 protected:
00088   double Marq_lambda;
00089   void **param;
00090   double numy,ldet;
00091   int aireml_called;
00092   int Need_Ainv, Need_Residual,res_nvc,Return_Stat,do_west,num_west,AI_sample;
00093   int Print_Level,PEV_Scale,Use_Like,Print_Summary,Update_estimate,Sand_Calc,LM,Need_PEV;
00094   Observe * observation;
00095   doubleMatrix  * SinMat;
00096   doubleMatrix  * varinv, *Var;
00097   doubleMatrix  **corrvar;
00098   doubleMatrix  CorrVar;
00099   int     ncorr,*corrmap;
00100   doubleMatrix  Info;
00101   Vector<double> Score;
00102   Vector<double> varcomp,varest;
00103   Vector<int> kvec;
00104   double like_val,like_adj;
00105   doubleMatrix Fmat,FRHS,FSol;
00106   SparseMatrix hainv;
00107   SparseMatrix hSand,hInv;
00108   SparseMatrix itilde,ihat,jtilde,jhat,S;
00109   Vector<double> sol_null,qhat;
00110   void (*link_function)(Observe &);
00111   Vector<double> Initial;
00112   int Asym,LR;
00113 public:
00114   int nrandom;  ////// act_numtrait added by TW
00115   int num_glmm;  //// Number of iterations of glim during each round of ai_reml
00116   int *nt_vec2; 
00117   GLMM() {observation = 0;SinMat=0;Need_Ainv=1;varinv=0;like_val=0;Need_PEV=0;
00118   Var=0;link_function=0;Need_Residual=0;res_nvc=0;Print_Level=0;Print_Summary=0;Asym=0;LR=0;PEV_Scale=1;Use_Like=0;Sand_Calc=0;LM=0;Return_Stat=0;do_west=0;num_west=0;numy=0;
00119   param=0;Marq_lambda=1.;Update_estimate=1;ncorr=0;corrmap=0,corrvar=0;nrandom=0;nt_vec2=0;AI_sample=0;aireml_called=0;num_glmm=3;};
00120   ~GLMM()
00121     {release_obs();
00122     release_SinMat();
00123     int i;if(varinv){
00124       for(i=0;i<numterm;i++)varinv[i].resize(0,0);delete [] varinv; varinv=0;
00125     }
00126     if (Var){
00127       for(i=0;i<numterm;i++)Var[i].resize(0,0); delete [] Var;Var=0;
00128     }
00129     if(corrvar) {
00130       for(int i=0;i<numterm;i++) {
00131         delete [] corrvar[i];
00132       }
00133       delete corrvar;corrvar=0;;
00134     }
00135     if(corrmap) delete [] corrmap;corrmap=0;
00136     if(nt_vec2) delete [] nt_vec2;nt_vec2=0;
00137     };
00138   void SSQCP(void);
00139   void **Param(void **par=0) {if(par) param=par;return(param);}
00140   int Large_Sample(int Sample=-1) {if(Sample != -1) Asym=Sample;return(Asym);}
00141   int Pev_scale(int Sample=-1) {if(Sample != -1) PEV_Scale=Sample;return(PEV_Scale);}
00142   int LR_Test(int LR_set=-1) {if(LR_set != -1) LR=LR_set;return(LR);} //LR=0 WALD LR=1 LR LR=2 LM
00143   int LM_Test(int LM_set=-1) {if(LM_set != -1) LM=LM_set;return(LM);}
00144   int Data_static(int DS_set=-1) {if(DS_set != -1) data_static=DS_set;return(data_static);}
00145   int Like_LR(int L_set=-1) {if(L_set != -1) Use_Like=L_set;return(Use_Like);}
00146   int Westell(int W_set=-1) {if(W_set != -1) do_west=W_set;return(do_west);}
00147   int AI_Sample(int S_set=-1) {if(S_set != -1) AI_sample=S_set;return(AI_sample);}
00148   void Initial_eta(Vector<double> initial){Initial=initial;}
00149   void residual(int get_pev=0);
00150   void new_SinMat(void);
00151   double log_likelihood(int solve=1);
00152   double restricted_log_likelihood(int solve=1);
00153   void release_SinMat(void);
00154   void Build_SinMat(void);
00155   int print_level(int level=-99) {if(level !=-99) Print_Level=level; return(Print_Level);}
00156   int return_stat(int level=-99) {if(level !=-99) Return_Stat=level; return(Return_Stat);}
00157   int print_summary(int level=-99) {if(level !=-99) Print_Summary=level; return(Print_Summary);}
00158   Observe* get_obs(void) {return observation;}
00159   doubleMatrix* get_SinMat(void) {return SinMat;}
00160   Vector<double>& resid(int i){return observation[i].residual;}
00161   Vector<double>& Linear_Predictor(int i){return observation[i].estimate;}
00162   doubleMatrix& pev(int i) {return observation[i].pev;}
00163   double log_like(void) {return like_val;}
00164   doubleMatrix INFO(void) {return Info;}
00165   Vector<double> SCORE(void) {return Score;}
00166   Observe& new_obs();
00167   void release_obs();
00168   SparseMatrix& ainv(void);
00169   unsigned Numrec(void) {return numrec;};
00170   doubleMatrix AI_REML(int numiter=10,double tol=1.e-4,double info_scale=0);
00171   virtual      SparseMatrix*  setup_mme(Vector<double> *rhs=0);
00172   void link(void (*link_fn)(Observe &),int rvc=0) {link_function=link_fn;if(res_nvc!=rvc){res_nvc=rvc,varcomp.resize(res_nvc);}}
00173   unsigned TotalNvc(void) const;
00174   int Var2Vec(double *x);
00175   void Vec2Var(const double *x);
00176   void covariance_old(const std::string &termname,const std::string &termname2,const doubleMatrix& v);
00177   Vector<double>* glim(int iterations=10,double **ke=0, int nr=0,int nc=0,double *mean=0);
00178   void add_G_Sand(void);
00179   void add_IgSand(int t);
00180   void add_AgSand(int t);
00181   void add_Ag(int t,int ct);
00182   void add_Ag(int t, SparseMatrix &h);
00183   void add_Ag_old(int t);
00184   void add_Ig(int t, SparseMatrix &h);
00185   void add_G_1(SparseMatrix &h);
00186   void add_G_1_old();
00187   void build_CorrVar(void);
00188   void build_hInv(void);
00189   void info(std::ostream &stream);
00190   void save(const std::string &fname, const int io_mode=std::ios::out);//SDK |std::ios::noreplace);
00191 #ifdef GLMM_QUAD
00192   double quad(double *x, double *y, double *xsol, double *ysol, int path=3);
00193 #endif
00194   void normalLog(void);
00195   doubleMatrix getVarEstimates(const std::string &termname);
00196 };
00197 
00198 doubleMatrix *KP(Data *D,doubleMatrix &SKM,const std::string &lpl,const std::string &censor);
00199 
00200 doubleMatrix operator*(Vector<double> &a,Vector<double> &b);
00201 //Vector<double> operator*(Vector<double> &a,Vector<double> &b);
00202 
00203 void bound_pd (double *varnew, int ntrait, doubleMatrix & P);
00204 } ///////// end of namespace matvec
00205 #endif

Generated on Thu Jun 16 17:13:41 2005 for Matvec by doxygen1.2.16