1
#############################################
2
# Linear regression fit/predict converters
3
#############################################
7
.JNew('org.openscience.cdk.qsar.model.R.LinearRegressionModelFit',
8
obj$coefficients, obj$residuals,
9
obj$fitted, obj$rank, obj$df.residual)
11
lmPredictConverter <- function(preds,...) {
12
.JNew('org.openscience.cdk.qsar.model.R.LinearRegressionModelPredict',
13
preds$fit[,1], preds$se.fit, preds$fit[,2], preds$fit[,3],
14
preds$df, preds$residual.scale)
16
lmSummaryConverter <- function(sumry,...) {
17
.JNew('org.openscience.cdk.qsar.model.R.LinearRegressionModelSummary',
18
sumry$residuals, sumry$coeff,
19
sumry$sigma, sumry$r.squared, sumry$adj.r.squared,
20
sumry$df[2], sumry$fstatistic,
21
attr(sumry$coeff, 'dimnames')[[1]],
22
attr(sumry$coeff, 'dimnames')[[2]])
25
buildLM <- function(modelname, params) {
26
# params is a java.util.HashMap containing the parameters
27
# we need to extract them and add them to this environment
28
paramlist <- hashmap.to.list(params)
31
# x will come in as a double[][]
32
x <- matrix(unlist(x), nrow=length(x), byrow=TRUE)
34
# assumes y ~ all columns of x
35
d <- data.frame(y=y,x)
36
assign(modelname, lm(y~., d, weights=weights), pos=1)
41
predictLM <- function( modelname, params) {
42
# params is a java.util.HashMap containing the parameters
43
# we need to extract them and add them to this environment
44
paramlist <- hashmap.to.list(params)
47
newx <- data.frame( matrix(unlist(newdata), nrow=length(newdata), byrow=TRUE) )
48
names(newx) <- names(get(modelname)$coef)[-1]
49
if (interval == '' || !(interval %in% c('confidence','prediction')) ) {
50
interval = 'confidence'
52
preds <- predict( get(modelname), newx, se.fit = TRUE, interval=interval);
53
class(preds) <- 'lmregprediction'