jeffreyevans/yaImpute

predict.yai error "no observations"

Closed this issue · 3 comments

I am trying to use the funtion "predict.yai" on new data but I get an error saying "Error in newtargets(object, newdata, al$k, al$ann) : no observations". I am not sure what the error means or what is causing the error. I have tried to find examples for predicting on new data but I could not find any.

This is a small reproducible example based on the data MoscowMtJoe:

data("MoscowMtStJoe")
x <- MoscowMtStJoe[, c("EASTING", "NORTHING", "ELEVMEAN",
                       "SLPMEAN", "ASPMEAN", "INTMEAN", "HTMEAN", "CCMEAN")]
x[, 5] <- (1 - cos((x[, 5] - 30) * pi/180))/2
names(x)[5] = "TrASP"
y <- MoscowMtStJoe[, c(1, 9, 12, 14, 18)]

# Create yai object
mal <- yai(x = x, y = y, method = "mahalanobis")

# Create a new dataset with 30 observations based on original x but adding a bit of variance
nd = x[sample(rownames(x), nrow(x)),]+runif(nrow(x), min = -0.1, max = 0.1)
nd = nd[1:30,]
rownames(nd) = 1:nrow(nd)

# predict
predict.yai(object = mal, newdata = nd)

Of course Nick nailed the issue. I change the rowname assignment in your code so that it was not duplicate with the references and it worked.

rownames(nd) = paste0("n",1:nrow(nd))

Great! It worked and computed the predictions. Thanks!

However, I have another question. I will post it in a separate issue.