[R] problem with predict()

Czerminski, Ryszard ryszard at arqule.com
Thu Jun 20 21:18:44 CEST 2002


Hi,

It is most probably just my R-ignorance, but I have following problem with 
using predict(). I train the model using 164 cases and then I try to use
it on the data set with 35 cases, but I am getting 164 predictions ?

R-code below illustrates in more detail what I am doing.

Truly yours,

R

train = read.csv("train.csv", header = TRUE, row.names = "mol",
comment.char="")

yr <- train[,1]              # take Y from 1 column
xr <- train[,-1]        # X is the rest
xr <- scale(xr)     # matrix <- scale(data.frame)
x.center <- attr(xr, "scaled:center")
x.scale <- attr(xr, "scaled:scale")
mask <- apply(xr, 2, function(x) any(is.na(x)))
xr <- xr[,!mask] # rm NA's
model <- lm(yr ~ xr) # fit linear model

test <- read.csv("test.csv", header = TRUE, row.names = "mol",
comment.char="")

ys <- test[,1]
xs <- test[,-1]
xs <- scale(xs, center = x.center, scale = x.scale)
xs <- xs[,!mask]
xs <- as.data.frame(xs)

pr <- predict(model, as.data.frame(xr))
ps <- predict(model, xs)

cat("length(yr) =", length(yr), "; length(pr) =", length(pr),"\n")
cat("dim(xr) =", dim(xr), "; dim(xs) =", dim(xs),"\n")
cat("length(ys) =", length(ys), "; length(ps) =", length(ps), "\n")
cat("why length(ps) != length(ys) ???\n")

# my output:
#
# length(yr) = 164 ; length(pr) = 164 
# dim(xr) = 164 118 ; dim(xs) = 35 118 
# length(ys) = 35 ; length(ps) = 164 
# why length(ps) != length(ys) ???

Ryszard Czerminski   phone: (781)994-0479
ArQule, Inc.         email:ryszard at arqule.com
19 Presidential Way  http://www.arqule.com
Woburn, MA 01801     fax: (781)994-0679


-----Original Message-----
From: Czerminski, Ryszard [mailto:ryszard at arqule.com]
Sent: Thursday, June 20, 2002 12:15 PM
To: r-help at stat.math.ethz.ch
Subject: [R] dist(a,b) ???


Is there a function analogous to "dist" which would
calculate distances between rows of two different data sets ?

Ryszard Czerminski   phone: (781)994-0479
ArQule, Inc.         email:ryszard at arqule.com
19 Presidential Way  http://www.arqule.com
Woburn, MA 01801     fax: (781)994-0679

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list