Final

Documentation of the code in experiment_floodplain/final. These scripts create the figures and the tables in the paper.

Scripts for visualization of results

Script task_plot_beliefs.py

This script produces all the figures related to prior and posterior beliefs distributions, confidence in beliefs, and belief updating. The figures are saved in .PNG format in bld/figures/beliefs.

Script task_plot_information.py

This script produces all the figure related to survey respondents’ information quality. The figures are saved in .PNG format in bld/figures/information.

Script task_plot_wtp.py

This script produces the figures related to survey respondents’ elicited willingness-to-pay for insurance. The figures are saved in .PNG format in bld/figures/willingness_to_pay.

Scripts to create the .tex tables

In the folder task_fill_table_templates. All use the .txt templates in the folder table_templates and the data in bld/analysis. The .tex files are saved to bld/tables.

Auxiliary modules

In folder PYTHON.

Script visualize_beliefs.py

Visualization module for task_plot_beliefs.py.

add_variables_for_plotting(df, edges, labels_damages)[source]

Add variables for plotting figures.

get_labels_dictionary(all_ticks, ticks_to_show)[source]

Create dictionary of labels for plot.

histogram_scatterplot_belief_distributions(df, x, y, xlabel)[source]

Plot histogram and scatterplot of x vs. y from Pandas.DataFrame df.

make_jointplot(df, x, y, title, axis_spaced_by_5=False)[source]

Make jointplot of varables x and y in Pandas.DataFrame df, with title.

plot_all_histograms_belief_vs_confidence(dict_keys, df, xs, ys, list_of_bins, xlabels, list_of_xticks, labels_dicts, add_missings, type)[source]

Plot multiple histograms of beliefs vs. average confidence in beliefs, and add them to a dictionary.

Parameters:
  • dict_keys (list) – Keys of dictionary of results, one for each figure.

  • df (Pandas.DataFrame) – Dataframe with columns to plot.

  • xs (list of str) – Names of columns to be plotted on the x-axis (values of reported beliefs).

  • ys (list of str) – Names of columns to be plotted on the y-axis (values of reported confidence in beliefs).

  • list_of_bins (list of lists) – List of lists of number of bins for histograms.

  • xlabels (list of str) – List of names for x-axis labels.

  • list_of_xticks (list of lists) – List of lists of x-axis coordinates for ticks.

  • labels_dicts (list of lists) – Whether to rename x-axis ticks.

  • add_missings (list of bool) – List of whether to include columns with missing values in the final histograms.

  • type (list of str) – List of type of plot for average confidence, either “barplot” or “pointplot”.

Returns:

dictionary.

plot_histogram_belief_vs_confidence(df, x, y, xlabel, xticks, bins, labels_dict=False, add_missing_values=False, rotation=0, type='barplot')[source]

“Plot histogram of beliefs vs. average confidence in beliefs.

Parameters:
  • df (Pandas.DataFrame) – Dataframe with columns to plot.

  • x (str) – Name of column to be plotted on the x-axis (values of reported beliefs).

  • y (str) – Name of columns to be plotted on the y-axis (values of reported confidence in beliefs).

  • xlabel (str) – Name for x-axis label.

  • xticks (list of int) – List of x-axis coordinates for ticks.

  • bins (list of int) – Number of histogram bins.

  • labels_dict (dict) – Optional, dictionary of x-axis ticks and x-axis ticks’ labels.

  • add_missing_values (bool) – Whether to include columns with missing values in the final histograms, default is False.

  • rotation (int) – Rotation of x-axis ticks, default is 0.

  • type (str) – Type of plot for average confidence, either “barplot” (default) or “pointplot”.

  • Returns – matplotlib.Figure.

plot_lower_triangular_heatmap(df_corr, suptitle, n_obs, cmap)[source]

Plot lower triangular heatmap depicting correlation between answers to multiple choice questions (on measures against flood or sources consulted about flood risk).

Parameters:
  • df (Pandas.DataFrame) – Dataframe of two-ways correlations.

  • suptitle (Str) – Plot main title.

  • n_obs (int) – Number of observations. Will be written in the plot sub-title.

  • cmap (palette) – Seaborn palette.

Returns:

Matplotlib.Figure

plot_updates(df, query_strings, titles, xlabel, ylabel, figsize)[source]

Plot belief updates by direction implied by baseline information quality.

Parameters:
  • df – Dataset containing variables of interest.

  • query_strings – Strings to select variables of interest.

  • titles – Titles of sub-figures.

  • xlabel – x-axis label.

  • ylabel – y-axis label.

  • figsize – Figure size.

Returns:

matplotlib.Figure.

Script visualize_information.py

Visualization module for task_plot_information.py.

get_df_for_plotting(df, noise)[source]

Melt dataframe df so that each answer to an information-based question is classified as correct or incorrect (value 1 or 0), by topic (flood maps, insurance, government compensation), and by confidence in the answer (number from 1 to 10).

Parameters:
  • df (Pandas.DataFrame) – Dataframe of interest

  • noise (float) – Add noise to confidence variable. Useful to get a nicer swarmplot.

Returns:

Pandas.DataFrame

plot_information_vs_confidence(df, noise=0)[source]

Create a Seaborn swarmplot showing confidence level for incorrect vs. correct answers.

plot_total_information_vs_confidence(df)[source]

Plot two histograms next two each other.

The first histogram has number of information frictions on the x-axis and share of survey respondets on the y-axis.

The second histogram has average confidence in answers to information-based questions on the x-axis and share of survey respondents on the y-axis.

The Pandas.DataFrame df needs to contain the columns “total_frictions” and “average_info_confidence”.

scatter_dataframe(df, cols, increment)[source]

Scatter valued of cols in df, by increment.

Args:

df (Pandas.DataFrame): Dataset. cols (list of strings): Column(s) of df whose values should be scattered. increment (float): By how much should the values of cols be scattered.

Returns:

Pandas.DataFrame.

Script visualize_wtp.py

Visualization module for task_plot_wtp.py.

plot_insurance_two_arms(data)[source]

Plot who stays and leaves the flood insurance market, by flood risk category and treament arms (“Neutral text” vs. “Risk profile”). Include average WTP by flood risk category for those who stay.

Script format_tables.py

Functions to format tables.

get(data, index1, index2=None)[source]

Get values from specified index position of Pandas.DataFrame data, as list, excluding NaNs.

split_dataset(df, cols, p_val=False)[source]

Extract dataset of coefficients and of standard deviations from Pandas.DataFrame df and column nams cols. Add stars to coefficients according to pvalues.

update(key, n_keys, values, kwargs={})[source]

Create dictionary from key, n_keys and values and update whatever kwargs dictionary is in the global space.