diff --git a/code/3lc_nocov.R b/code/3lc_nocov.R index 4a780c87f9ff6eccef3509a4526ea8e221cb7736..3708e3224378b6b596a5df993f7eccee22bfeaf1 100644 --- a/code/3lc_nocov.R +++ b/code/3lc_nocov.R @@ -180,8 +180,8 @@ lc3cl[["unconditionals"]] <- apollo_lcUnconditionals(lc3cl,apollo_probabilities, apollo_saveOutput(lc3cl, saveOutput_settings = list(saveEst=FALSE, savbmetv=FALSE, savbmetrr=FALSE)) +lc3lc_model <- choiceTools::quicktexregapollo(lc3cl) - - +saveRDS(lc3lc_model, file = "modeloutput/lcmodelstex.RDS") diff --git a/code/readmodels.R b/code/readmodels.R index 833514eb49baaf743bc8f3ff4dfc23730ffe925f..2e53bf6caf9e3699f1d030d7b24ce01badb76108 100644 --- a/code/readmodels.R +++ b/code/readmodels.R @@ -1,9 +1,42 @@ -deleteold <-list.files("modeloutput/clogit/", pattern = "OLD", full.names=TRUE) +deleteold <-list.files("modeloutput", pattern = "OLD", full.names=TRUE , recursive = TRUE) file.remove(deleteold) mnlsplits<-readRDS("modeloutput/modelstex.RDS") -lc3cl_model <- readRDS("~/share/groups/bioecon/Julian/seminarheuristics/modeloutput/lclogit/lc3cl_model.rds") \ No newline at end of file +lc3cl_model <- readRDS("modeloutput/lcmodelstex.RDS") + +remGOF + + + +class1 <- lc3cl_model +class2 <- lc3cl_model +class3 <- lc3cl_model + + + for (ele in c("coef.names","coef","se","pvalues")) { + elements<- slot(class1,ele)[1:7] + slot(class1,ele) <- elements + +} + + +for (ele in c("coef.names","coef","se","pvalues")) { + elements<- slot(class2,ele)[9:15] + slot(class2,ele) <- elements + +} + +for (ele in c("coef.names","coef","se","pvalues")) { + elements<- slot(class3,ele)[17:23] + slot(class3,ele) <- elements + +} + +allclasses <- remGOF(list(class2, class3)) + +allclasses[["class1"]] <-class1 + diff --git a/modeloutput/lcmodelstex.RDS b/modeloutput/lcmodelstex.RDS new file mode 100644 index 0000000000000000000000000000000000000000..e12f561e193b65e03ed5f63e7f97f3ec19849da3 Binary files /dev/null and b/modeloutput/lcmodelstex.RDS differ diff --git a/oldslides.R b/oldslides.R deleted file mode 100644 index 31c76c2af265d04937ddb93653f6271022673bc1..0000000000000000000000000000000000000000 --- a/oldslides.R +++ /dev/null @@ -1,64 +0,0 @@ -## Example data set - -- We use a choice experiment with three attributes and two alternatives. There is no opt-out option. The design is a simple full factorial. - -## Attributes -<div class=".hscroll"> - +-------------------------------+------------------+---------------------------------+ - | Attribute | Levels | Coding | - +===============================+==================+=================================+ - | Country of Tofu manufacturing | Non EU | 0 0 | - | | | | - | | EU | 1 0 | - | | | | - | | Sweden | 0 1 | - +-------------------------------+------------------+---------------------------------+ - | Country of origin of soybean | Non EU | 0 0 | - | | | | - | | EU | 1 0 | - | | | | - | | Sweden | 0 1 | - +-------------------------------+------------------+---------------------------------+ - | Cultivation of Soybean | Conventional | 0 | - | | | | - | | Organic | 1 | - +-------------------------------+------------------+---------------------------------+ - | Price per 400g in SEK | 15 SEK to 60 SEK | Continuous with original values | - +-------------------------------+------------------+---------------------------------+ - - - ## Attributes - - ```{r attributes} - df <- data.frame( - Attribute = c( - "Country of tofu manufacturing", - "Country of origin of soybean", - "Cultivation of Soybean", - "Price per 400g in SEK" - ), - Levels = c( - "Non EU | EU | Sweden", - "Non EU | EU | Sweden", - "Conventional | Organic", - "15 SEK to 60 SEK" - ), - Coding = c( - "0 | Dummy", - "0 | Dummy", - "0 | 1", - "Continuous with original values" - ) - ) - - - # Print the data frame using kable - kable(df) %>% kable_styling(full_width = TRUE, position = "center") - - ``` - - - ## Example Choice Set - -  - \ No newline at end of file diff --git a/slides.html b/slides.html index b6ce1cdda838d79ab91c21d2b0429d805b4bb330..170806cf66f7adcc2387911152a3120c7032a452 100644 --- a/slides.html +++ b/slides.html @@ -344,9 +344,11 @@ <li><a href="#/data-generating-processes">Data generating processes</a></li> <li><a href="#/example-feed-additives">Example: Feed Additives</a></li> <li><a href="#/simulated-dataset">Simulated dataset</a></li> -<li><a href="#/heuristics">Heuristics</a></li> <li><a href="#/regression-results-with-all-models">Regression results with all models</a></li> <li><a href="#/latent-class-models">Latent Class models</a></li> +<li><a href="#/summary">Summary</a></li> +<li><a href="#/way-forward">Way forward</a></li> +<li><a href="#/now-it-is-your-turn">Now it is your turn</a></li> </ul> </nav> </section> @@ -7062,7 +7064,7 @@ Log Likelihood (Converged) </div> </div> </section> -<section id="heuristics" class="slide level2"> +<section id="heuristics" class="slide level2 unnumbered unlisted smaller"> <h2>Heuristics</h2> <ul> <li><p>In the data there are three different DGPs</p></li> @@ -7076,7 +7078,7 @@ Log Likelihood (Converged) <p><span class="math display">\[ U = \alpha + \beta_{cow}\text{cow}+\beta_{adv}\text{adv} + \beta_{vet}\text{vet} + \beta_{far}\text{far}+\beta_{bon}\text{bon} + \epsilon\]</span></p> <ul> -<li>Group 3 (20%): Only Bonus with $ _{bon2}=1.9$</li> +<li>Group 3 (20%): Only Bonus with $ _{bon2}=1.9 $</li> </ul> <p><span class="math display">\[ U = \beta_{bon2}\text{bon} + \epsilon\]</span></p> </section> @@ -7095,15 +7097,12 @@ Log Likelihood (Converged) <li><p><a href="./choicesets.html">All respondents</a></p></li> <li><p><a href="./choicesets_rum.html">RUM</a></p></li> <li><p><a href="./choicesets_nonattendence.html">Attribute Non-Attendence</a></p></li> -<li><p><a href="./choicesets_priceheuristic.html">Price Heuristics</a></p></li> +<li><p><a href="./choicesets_priceheuristic.html">Bonus Heuristics</a></p></li> </ul> </section> <section id="regression-results-with-all-models" class="slide level2 smaller"> <h2>Regression results with all models</h2> <table class="texreg" style="margin: 10px auto;border-collapse: collapse;border-spacing: 0px;caption-side: bottom;color: #000000;border-top: 2px solid #000000;"> -<caption> -Statistical models -</caption> <thead> <tr> <th style="padding-left: 5px;padding-right: 5px;"> @@ -7317,7 +7316,214 @@ Log Likelihood (Converged) <section id="latent-class-models" class="slide level2"> <h2>Latent Class models</h2> <ul> -<li>We may try a Latent Class model to detect heuristics</li> +<li><p>We may try a latent class model to detect heuristics</p></li> +<li><p>In the ideal case, we would find two classes of about 20 % and one class with about 60%</p></li> +<li><p>The classes would reflect the DGP in the three groups</p></li> +</ul> +</section> +<section id="regression-results-latent-class" class="slide level2 unnumbered unlisted smaller"> +<h2>Regression results Latent Class</h2> +<table class="texreg" style="margin: 10px auto;border-collapse: collapse;border-spacing: 0px;caption-side: bottom;color: #000000;border-top: 2px solid #000000;"> +<thead> +<tr> +<th style="padding-left: 5px;padding-right: 5px;"> + +</th> +<th style="padding-left: 5px;padding-right: 5px;"> +Class 1: 15% +</th> +<th style="padding-left: 5px;padding-right: 5px;"> +Class 2: 20% +</th> +<th style="padding-left: 5px;padding-right: 5px;"> +Class 3: 65% +</th> +</tr> +</thead> +<tbody> +<tr style="border-top: 1px solid #000000;"> +<td style="padding-left: 5px;padding-right: 5px;"> +basc +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.35 (0.13)<sup>**</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-17.01 (9.81)<sup>*</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-0.03 (0.01)<sup>***</sup> +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +bcow +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.09 (0.06) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-0.21 (0.07)<sup>**</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.37 (0.03)<sup>***</sup> +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +badv +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-0.31 (0.21) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-15.47 (9.75) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.31 (0.03)<sup>***</sup> +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +bvet +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-0.23 (0.16) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-7.75 (7.61) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.15 (0.02)<sup>***</sup> +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +bfar +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-0.23 (0.34) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-7.75 (3.83)<sup>*</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.14 (0.02)<sup>***</sup> +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +bmet +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.66 (0.14)<sup>***</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +8.21 (4.85)<sup>*</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.15 (0.03)<sup>***</sup> +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +bbon +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.33 (0.03)<sup>***</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +18.04 (9.72)<sup>*</sup> +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +0.29 (0.01)<sup>***</sup> +</td> +</tr> +<tr style="border-top: 1px solid #000000;"> +<td style="padding-left: 5px;padding-right: 5px;"> +No Observations +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +28800 +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +No Respondents +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +3600 +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +</tr> +<tr> +<td style="padding-left: 5px;padding-right: 5px;"> +Log Likelihood (Null) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-31640.03 +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +</tr> +<tr style="border-bottom: 2px solid #000000;"> +<td style="padding-left: 5px;padding-right: 5px;"> +Log Likelihood (Converged) +</td> +<td style="padding-left: 5px;padding-right: 5px;"> +-19918.67 +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +<td style="padding-left: 5px;padding-right: 5px;"> + +</td> +</tr> +</tbody> +</table> +</section> +<section id="summary" class="slide level2"> +<h2>Summary</h2> +<ul> +<li><p>Heuristics are likely present in the DGP</p></li> +<li><p>Presence of heuristics violates standard RUM modelling</p></li> +<li><p>Not accounting for heuristics can lead to biases</p></li> +<li><p>How severe the biases are depends</p></li> +<li><p>Latent class models are not necessarily useful</p></li> +</ul> +</section> +<section id="way-forward" class="slide level2"> +<h2>Way forward</h2> +<ul> +<li><p>Check the data manually</p></li> +<li><p>Try to identify respondents who apply some standard heuristics</p></li> +<li><p>Identifying respondents who only regard one attribute may be easy</p></li> +<li><p>Attribute Non attendence models may help as well (see tomorrow)</p></li> +</ul> +</section> +<section id="now-it-is-your-turn" class="slide level2"> +<h2>Now it is your turn</h2> +<ul> +<li><p>You find the dataset <code>feedadd_data_practice.RDS</code>in the folder <code>data</code></p></li> +<li><p>Have a look at the data and try to identify heuristics by either looking at choice frequencies or estimated models</p></li> +<li><p>Estimate a four class LC model</p></li> +<li><p>Try to write code that identifies a Bonus heuristic</p></li> </ul> <img src="iDiv_Logo_long.png" class="slide-logo r-stretch"><div class="footer footer-default"> diff --git a/slides.qmd b/slides.qmd index aa23e884fec766566deeee392b31aae9b14d90bb..149643dd8ef129a83c953efab80f84273c58a775 100644 --- a/slides.qmd +++ b/slides.qmd @@ -43,7 +43,6 @@ source("code/readmodels.R") - - Often we assume a data generating process that aligns with the standard models we use for analysis - Random utility model with Gumbel iid errors @@ -178,7 +177,7 @@ kable(head(feedadd_data,n = 200)) %>% kable_styling(bootstrap_options = "striped scroll_box(height = "600px", width = "100%") ``` -## Heuristics +## Heuristics {.unnumbered .unlisted .smaller} - In the data there are three different DGPs @@ -192,7 +191,7 @@ $$ U = \alpha + \beta_{cow}\text{cow}+\beta_{adv}\text{adv} + \beta_{vet}\text{v $$ U = \alpha + \beta_{cow}\text{cow}+\beta_{adv}\text{adv} + \beta_{vet}\text{vet} + \beta_{far}\text{far}+\beta_{bon}\text{bon} + \epsilon$$ -- Group 3 (20%): Only Bonus with $ \beta\_{bon2}=1.9$ +- Group 3 (20%): Only Bonus with $ \beta\_{bon2}=1.9 $ $$ U = \beta_{bon2}\text{bon} + \epsilon$$ @@ -214,7 +213,7 @@ $$ U = \beta_{bon2}\text{bon} + \epsilon$$ - [Attribute Non-Attendence](./choicesets_nonattendence.html) -- [Price Heuristics](./choicesets_priceheuristic.html) +- [Bonus Heuristics](./choicesets_priceheuristic.html) ## Regression results with all models {.smaller} @@ -227,4 +226,49 @@ texreg::htmlreg(mnlsplits, single.row = TRUE , custom.note = "" , html.tag = FAL - We may try a latent class model to detect heuristics +- In the ideal case, we would find two classes of about 20 % and one class with about 60% + +- The classes would reflect the DGP in the three groups + + + + +## Regression results Latent Class{.unnumbered .unlisted .smaller} + +```{r lcreg, results='asis'} +texreg::htmlreg(list(allclasses[["class1"]], allclasses[[1]],allclasses[[2]]), single.row = TRUE , custom.note = "" , html.tag = FALSE, head.tag = FALSE , body.tag = FALSE, caption = "", custom.model.names = paste0("Class ", 1:3 ,c(": 15%",": 20%",": 65%" ))) +``` + + +## Summary + +- Heuristics are likely present in the DGP + +- Presence of heuristics violates standard RUM modelling + +- Not accounting for heuristics can lead to biases + +- How severe the biases are depends + +- Latent class models are not necessarily useful + +## Way forward + +- Check the data manually + +- Try to identify respondents who apply some standard heuristics + +- Identifying respondents who only regard one attribute may be easy + +- Attribute Non attendence models may help as well (see tomorrow) + +## Now it is your turn + +- You find the dataset `feedadd_data_practice.RDS `in the folder `data` + +- Have a look at the data and try to identify heuristics by either looking at choice frequencies or estimated models + +- Estimate a four class LC model + +- Try to write code that identifies a Bonus heuristic