Definition of `newdata` in` posterior_linpred () `from the rstanarm R package

I am wondering why I get an error when trying to use an argument newdata posterior_linpred()from a package rstanarm?

The complete code below along with the error I get:

ps I follow a similar pattern as option 2 in This Demonstration .

 library(rstanarm) 
 data(kidiq)
 d <- kidiq  

 fit <- stan_glm(kid_score ~ mom_iq,
           data = d,   
           prior = normal(0, 2.5),  
           prior_intercept = normal(0, 10),  
           prior_aux = cauchy(0, 10)) 


pred.range = min(d$mom_iq):max(d$mom_iq)

newdata <- data.frame(observation = 1:length(pred.range), pred.range = pred.range)

pred_lin <- posterior_linpred(fit, newdata = newdata)

#==========================================
    Error in dimnames(x) <- dn : 
    length of 'dimnames' [2] not equal to array extent
    In addition: Warning messages:
    1: 'newdata' had 68 rows but variables found have 434 rows 
    2: In sweep(eta, 2L, offset, `+`) :
    STATS does not recycle exactly across MARGIN
0
source share

Source: https://habr.com/ru/post/1693763/


All Articles