void tabulaterun(dataobject & o) { // datamatrix X; unsigned i; vector<ST::string> vnames = o.m.getModelVarnamesAsVector(); // testing, wether all variables specified are already existing vector<ST::string> notex; bool failure=false; if ((o.allexisting(vnames,notex)) == false) { for (i=0;i<notex.size();i++) o.outerror("ERROR: variable " + notex[i] + " is not existing\n"); failure = true; } // end: if ((datap->allexisting(modelvarnamesv,notex)) == false) ST::string ifexpression = o.methods[9].getexpression(); if (failure==false) { // o.makematrix(vnames,X,ifexpression); // statmatrix<int> index(X.rows(),1); for(i=0;i<vnames.size();i++) { // o.m.makeModelMatrix_j(o.d,X,i); datamatrix Xi; o.makematrix(vnames[i],Xi,ifexpression); statmatrix<int> index(Xi.rows(),1); index.indexinit(); Xi.indexsort(index,0,Xi.rows()-1,0,0); o.out("\n"); o.out("Variable: " + vnames[i] + "\n",true, false, 14); o.out("\n"); unsigned k = 0; double cum = 0; unsigned zaehler = 0; while(k<index.rows() && zaehler<101) { double anz=0; int* p = index.getV() + k; int* q = index.getV() + k; for(unsigned j=k;j<index.rows();j++,p++) { if (Xi.get(*p,0) == Xi.get(*q,0)) anz = anz+1; } k = k + anz; zaehler = zaehler + 1; } if(zaehler>=101) o.outerror("ERROR: too many values"); else { ST::string value = "Value"; ST::string obs = "Obs"; ST::string freqst = "Freq"; ST::string cumst = "Cum"; o.out(value.helpfill(15) + obs.helpfill(10) + freqst.helpfill(15) + cumst.helpfill(15) + "\n",true); k = 0; while(k<index.rows()) { double anz=0; int* p = index.getV() + k; int* q = index.getV() + k; for(unsigned j=k;j<index.rows();j++,p++) { if (Xi.get(*p,0) == Xi.get(*q,0)) anz = anz+1; } double wert; wert = Xi.get(*q,0); double freq = anz / Xi.rows(); cum = cum + freq; ST::string str_wert = ST::doubletostring(wert,8); ST::string str_anz = ST::inttostring(anz); ST::string str_freq = ST::doubletostring(freq,4); ST::string str_cum = ST::doubletostring(cum,4); o.out(str_wert.helpfill(15) + str_anz.helpfill(10) + str_freq.helpfill(15) + str_cum.helpfill(15) + "\n"); k = k + anz; } } } o.out("\n"); } }
void pctilerun(dataobject & o) { datamatrix X; unsigned i; vector<ST::string> vnames = o.m.getModelVarnamesAsVector(); ST::string ifexpression = o.methods[10].getexpression(); // testing, wether all variables specified are already existing vector<ST::string> notex; bool failure=false; if ((o.allexisting(vnames,notex)) == false) { for (i=0;i<notex.size();i++) o.outerror("ERROR: variable " + notex[i] + " is not existing\n"); failure = true; } // end: if ((datap->allexisting(modelvarnamesv,notex)) == false) if (failure==false) { o.makematrix(vnames,X,ifexpression); o.out("\n"); //Ausgabe: //ST::string varst = "Variable"; //ST::string for(i=0;i<vnames.size();i++) { // o.m.makeModelMatrix_j(o.d,X,i); o.out("Variable: " + vnames[i] + "\n",true, false, 14); o.out("\n"); for(unsigned j=1; j<6; j++) { double quant = X.quantile(j,i); ST::string quantst = ST::doubletostring(quant,8); o.out(" " + ST::inttostring(j) + "%" + quantst.helpfill(15) + "\n"); } unsigned j = 25; while(j<=75) { double quant = X.quantile(j,i); ST::string quantst = ST::doubletostring(quant,8); o.out(ST::inttostring(j) + "%" + quantst.helpfill(15) + "\n"); j = j + 25; } for(unsigned j=95; j<100; j++) { double quant = X.quantile(j,i); ST::string quantst = ST::doubletostring(quant,8); o.out(ST::inttostring(j) + "%" + quantst.helpfill(15) + "\n"); } o.out("\n"); } } }
void descriptiverun(dataobject & o) { // datamatrix X; unsigned i; vector<ST::string> vnames = o.m.getModelVarnamesAsVector(); // testing, wether all variables specified are already existing vector<ST::string> notex; bool failure=false; if ((o.allexisting(vnames,notex)) == false) { for (i=0;i<notex.size();i++) o.outerror("ERROR: variable " + notex[i] + " is not existing\n"); failure = true; } // end: if ((datap->allexisting(modelvarnamesv,notex)) == false) ST::string ifexpression = o.methods[8].getexpression(); if (failure == false) { // o.makematrix(vnames,X,ifexpression); o.out("\n"); ST::string varst = "Variable"; ST::string obsst = "Obs"; ST::string meanst = "Mean"; ST::string medst = "Median"; ST::string stdst = "Std"; ST::string minst = "Min"; ST::string maxst ="Max"; o.out(varst.helpfill(11) + obsst.helpfill(10) + meanst.helpfill(15) + medst.helpfill(15) + stdst.helpfill(15) + minst.helpfill(15) + maxst.helpfill(15) + "\n",true); for(i=0;i<vnames.size();i++) { // o.m.makeModelMatrix_j(o.d,X,i); datamatrix Xi; o.makematrix(vnames[i],Xi,ifexpression); // für jede Variable eigene Matrix erzeugen? unsigned int obs = Xi.rows(); double mean = Xi.mean(0); double var = 0; if(obs > 1) var = Xi.var(0) * obs / (obs-1); ST::string str_std; if (var>0) { double std = sqrt(var); str_std = ST::doubletostring(std,8); } else { int std = 0; str_std = ST::inttostring(std); } double min = Xi.min(0); double max = Xi.max(0); double med = Xi.quantile(50,0); int l_vn = vnames[i].length(); if (l_vn > 9) { vnames[i] = vnames[i].substr(0, 9) + "~"; } ST::string str_obs = ST::inttostring(obs); ST::string str_mean = ST::doubletostring(mean,8); ST::string str_med = ST::doubletostring(med,8); ST::string str_min = ST::doubletostring(min,8); ST::string str_max = ST::doubletostring(max,8); o.out(vnames[i].helpfill(11) + str_obs.helpfill(10) + str_mean.helpfill(15) + str_med.helpfill(15) + str_std.helpfill(15) + str_min.helpfill(15) + str_max.helpfill(15) + "\n"); } o.out("\n"); } }