use of dr.inference.distribution.LinearRegression in project beast-mcmc by beast-dev.
the class GeneralizedLinearModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
// System.err.println("PASSED 0");
XMLObject cxo = xo.getChild(DEPENDENT_VARIABLES);
Parameter dependentParam = null;
if (cxo != null)
dependentParam = (Parameter) cxo.getChild(Parameter.class);
String family = xo.getStringAttribute(FAMILY);
GeneralizedLinearModel glm;
if (family.compareTo(LOGISTIC_REGRESSION) == 0) {
glm = new LogisticRegression(dependentParam);
} else if (family.compareTo(NORMAL_REGRESSION) == 0) {
glm = new LinearRegression(dependentParam, false);
} else if (family.compareTo(LOG_NORMAL_REGRESSION) == 0) {
glm = new LinearRegression(dependentParam, true);
} else if (family.compareTo(LOG_LINEAR) == 0) {
glm = new LogLinearModel(dependentParam);
} else
throw new XMLParseException("Family '" + family + "' is not currently implemented");
if (glm.requiresScale()) {
cxo = xo.getChild(SCALE_VARIABLES);
Parameter scaleParameter = null;
// DesignMatrix designMatrix = null;
Parameter scaleDesign = null;
if (cxo != null) {
scaleParameter = (Parameter) cxo.getChild(Parameter.class);
XMLObject gxo = cxo.getChild(INDICATOR);
if (gxo != null)
scaleDesign = (Parameter) gxo.getChild(Parameter.class);
// designMatrix = (DesignMatrix) cxo.getChild(DesignMatrix.class);
}
if (scaleParameter == null)
throw new XMLParseException("Family '" + family + "' requires scale parameters");
if (scaleDesign == null)
scaleDesign = new Parameter.Default(dependentParam.getDimension(), 0.0);
else {
if (scaleDesign.getDimension() != dependentParam.getDimension())
throw new XMLParseException("Scale (" + dependentParam.getDimension() + ") and scaleDesign parameters (" + scaleDesign.getDimension() + ") must be the same dimension");
for (int i = 0; i < scaleDesign.getDimension(); i++) {
double value = scaleDesign.getParameterValue(i);
if (value < 1 || value > scaleParameter.getDimension())
throw new XMLParseException("Invalid scaleDesign value");
scaleDesign.setParameterValue(i, value - 1);
}
}
glm.addScaleParameter(scaleParameter, scaleDesign);
}
// System.err.println("START 0");
addIndependentParameters(xo, glm, dependentParam);
// System.err.println("START 1");
addRandomEffects(xo, glm, dependentParam);
// System.err.println("START 2");
boolean checkIdentifiability = xo.getAttribute(CHECK_IDENTIFIABILITY, true);
if (checkIdentifiability) {
if (!glm.getAllIndependentVariablesIdentifiable()) {
throw new XMLParseException("All design matrix predictors are not identifiable in " + xo.getId());
}
}
// System.err.println("PASSED B");
checkFullRankOfMatrix = xo.getAttribute(CHECK_FULL_RANK, true);
// System.err.println("PASSED C");
return glm;
}
Aggregations