Giter VIP home page Giter VIP logo

Comments (2)

kronluk avatar kronluk commented on May 26, 2024

Hi all
First of all, thanks for an awesome package!

I have encountered a similar issue to barbosawf. For me, the problem is that there are less rows in the replacement compared to data when I add a 2D-spline to account for spatial effects in my model.
I can work around this by creating a custom Dtable (i.e. remove an "unused" row from model$Dtable) and specifying the Dtable argugment in predict.mmer.

Although this is a bit ugly, it seems to work in my case.
Yet, there seems to be a problem in the "if (is.null(Dtable) & is.character(D)) {...." part of predict.mmer and it would be good to have a proper solution.

Please find a reproducible example below.

Many thanks!

#==============================================
# Example

## sommer version: 4.3.2 (2023-09-01)
## R version 4.2.1 (2022-06-23 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 22621)
#==============================================

library(sommer)

# get data
data(DT_cpdata)
DT <- DT_cpdata
GT <- GT_cpdata
MP <- MP_cpdata

A <- A.mat(GT)

# fit basic model
m <- mmer(Yield~1,
          random = ~vsr(id, Gu=A) +
                    vsr(Rowf) +
                    vsr(Colf),
          rcov = ~vsr(units),
          data=DT,
          verbose = FALSE, dateWarning = FALSE)

# fit model using 2D p-spline for spatial correction
m_spl2Da <- mmer(Yield~1,
                 random = ~vsr(id, Gu=A) +
                           vsr(Rowf) +
                           vsr(Colf) +
                           spl2Da(Row,Col), 
                 rcov=~vsr(units),
                 data=DT, 
                 nIters = 3, verbose = FALSE, dateWarning = FALSE)

# predict
pr_m        <- predict(m,D="id") # works
pr_m_spl2Da <- predict(m_spl2Da,D="id")  # Error in `$<-.data.frame`(`*tmp*`, "start", value = c(1, 2, 365, 378,  : 
                                         # replacement has 5 rows, data has 6
m$Dtable
pr_m$Dtable

m_spl2Da$Dtable

# remove 'unused' row from Dtable and specify terms to be included/averaged
Dt <- m_spl2Da$Dtable
Dt[Dt$term == "1","include"] = TRUE
Dt[Dt$term == "1","average"] = TRUE
Dt[Dt$term == "id","include"] = TRUE
Dt <- Dt[-6,]

# predict by specifying 'custom' Dtable
pr_m_spl2Da<- predict(m_spl2Da,D="id",Dtable = Dt)
pr_m_spl2Da$Dtable

# inspect
summary(m)
summary(m_spl2Da)
plot(pr_m$pvals$predicted.value,pr_m_spl2Da$pvals$predicted.value) # prediction seems OK


from sommer.

covaruber avatar covaruber commented on May 26, 2024

I apologize for the slow response. The predict function for mmer() is indeed a headache, I am trying to rewrite all formulae of mmer but is taking me more than I thought. You can try mmec() and the predict function from that one. That second function uses the ideal formulae and is easy to keep the predict function easy to build.

from sommer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.