# NOT RUN {
#Data generation
# }
# NOT RUN {
K <- 2
# }
# NOT RUN {
X <- matrix(rnorm(20*K),20,K)
# }
# NOT RUN {
W <- matrix(rnorm(30*K),30,K)
# }
# NOT RUN {
U <- matrix(rnorm(3*K),3,K)
# }
# NOT RUN {
Y = 0
# }
# NOT RUN {
for(k in 1:K) Y <- Y + outer(outer(X[,k],W[,k]),U[,k])
# }
# NOT RUN {
Y <- Y + array(rnorm(20*30*3,0,0.25),dim=c(20,30,3))
# }
# NOT RUN {
#insert missing values
# }
# NOT RUN {
m.inds = sample(prod(dim(Y)),100)
# }
# NOT RUN {
Yobs = Y[m.inds]
# }
# NOT RUN {
Y[m.inds] = NA
# }
# NOT RUN {
#Run the method with default options and predict missing values
# }
# NOT RUN {
res <- tensorBF(Y)
# }
# NOT RUN {
pred = predictTensorBF(Y=Y,res=res)
# }
# NOT RUN {
plot(Yobs,pred[m.inds],xlab="obs",ylab="pred",main=round(cor(Yobs,pred[m.inds]),2))
# }
Run the code above in your browser using DataLab