Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predict.yai returns NAs for the observed values #2

Open
candelas762 opened this issue Jan 30, 2024 · 0 comments
Open

predict.yai returns NAs for the observed values #2

candelas762 opened this issue Jan 30, 2024 · 0 comments

Comments

@candelas762
Copy link

I do not understand the behaviour of the function predict.yai when I apply it to new data. It returns NAs for the observed values. Why is this happening?

I made a reroducible example based on the MoscowMtJoe data.

library(yaImpute)
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 data but adding a bit of variance
random = sample(rownames(x), nrow(x))

nd.y = y[random,] +runif(nrow(x), min = 0.1, max = 0.5)
nd.x = x[random,] +runif(nrow(x), min = 0.1, max = 0.5)

nd = cbind(nd.y, nd.x)[1:30,]
rownames(nd) = paste0("n",1:nrow(nd))

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

head(p)    # predicted
>      ABGR_BA PIPO_BA   PSME_BA     THPL_BA    Total_BA ABGR_BA.o PIPO_BA.o PSME_BA.o THPL_BA.o Total_BA.o
> n1 12.938903       0  1.201908  31.5207887  59.9378177        NA        NA        NA        NA         NA
> n2  2.447804       0 11.993483  30.8633313  56.4527989        NA        NA        NA        NA         NA
> n3  0.000000       0  0.000000   0.3806958   1.4782311        NA        NA        NA        NA         NA
> n4  0.000000       0  0.000000   0.0000000   0.3383963        NA        NA        NA        NA         NA
> n5  0.000000       0  6.746213   0.0000000   7.1332287        NA        NA        NA        NA         NA
> n6 10.357833       0  0.000000 244.8680129 255.4436635        NA        NA        NA        NA         NA

head(nd[,1:5]) # observed
>      ABGR_BA   PIPO_BA    PSME_BA     THPL_BA    Total_BA
> n1 13.2327991 0.2938965  1.4958040  31.8146852  60.2317142
> n2  2.6028360 0.1550319 12.1485148  31.0183632  56.6078308
> n3  0.2097972 0.2097972  0.2097972   0.5904930   1.6880283
> n4  0.1568212 0.1568212  0.1568212   0.1568212   0.4952175
> n5  0.4952800 0.4952800  7.2414930   0.4952800   7.6285087
> n6 10.6680486 0.3102155  0.3102155 245.1782284 255.7538790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant