leonsuetfeld / moraldm

0 stars 0 forks source link

Shrinkage in the logistic regression #3

Open behinger opened 5 years ago

behinger commented 5 years ago

I fitted the same model for once single subjects and once as a hierarchical model.

We should start with the Intercept grafik

Clearly we see strong shrinkage here.

We have a hard time to estimate the subject-wise choice bias just based on few trials. Therefore, shrinkage (in my opinion) does a great job here.

grafik

Here young_diff is strongly increased for all subjects.


model_single = choice_left ~
  1 + visonset_left + visonset_left:abstraction + (sex_diff + young_diff + elderly_diff)*speed*abstraction

priors_single <- c(set_prior("normal(0,3)", class = "b"))
mres_single = brm(model_single,
                  family=bernoulli,
                  data=d1.hum.effect%>%subset(sn_idx==1),
                  control = list(adapt_delta=0.9),
                  prior = priors_single)

all_subjects = NULL
for (s in unique(d1.hum.effect$sn_idx)){
  mres_single = update(mres_single,newdata=d1.hum.effect%>%subset(sn_idx==s))
  singlesub_result = mres_single%>%fixef%>%data.frame()
  singlesub_result$subject = s
  singlesub_result$effect = rownames(singlesub_result)
  all_subjects = rbind(all_subjects,singlesub_result)
}

all_subjects$type = 'subjectwise'
colnames(all_subjects)[c(3,4)] = c("2.5%","97.5%")

r = ranef(mres_full)$sn_idx
for (s in unique(d1.hum.effect$sn_idx)){
  r[s,,] = r[s,,]+t(fixef(mres_full))
}
r = reshape2::melt(r) %>% magrittr::set_colnames(c('subject','column','effect','value'))
r = reshape2::dcast(r,subject+effect~column)
r$type = 'hierarchical'
colnames(r)[c(5,6)] = c("2.5%","97.5%")
effects_combined = rbind(all_subjects,r)

ggplot(effects_combined%>%subset(effect == 'Intercept'),aes(x=Estimate,y=type,group=subject,xmin=`2.5%`,xmax=`97.5%`))+geom_line()+geom_point()#geom_errorbarh(height=0)
leonsuetfeld commented 5 years ago

Um sicher zu gehen, dass ich das hier verstehe:

Du hast ein mal ein Model wo jedes subject seinen eigenen Parametersatz hat und es kein sharing gibt, und dann hast du unser bekanntes Multi-Level Model im Vergleich. Und wir sehen, dass die Parameter näher zur Null gehen im Multi-Level.

Das ganze hier beinhaltet aber kein Single-Level Model (wo alle Subjects die gleichen Parameter hätten)?

behinger commented 5 years ago

Genau, das wäre eine dritte Zeile, kann ich noch einfügen - bin aber jetzt erstmal am IKW