Conjure

Conjure is a module for turning existing surveys, survey results and other data into EDSL objects.

For example, you can use it to turn a file of survey results into a Results object with an associated EDSL Survey, or a file of information about survey respondents or other populations into an AgentList.

Acceptable file formats for import are CSV (.csv), SPSS (.sav), and Stata (.dta).

How to use Conjure

  1. Create a Conjure object by passing the path to the file you want to import.

  2. Use the to_agent_list(), to_survey(), or to_results() methods to create the desired EDSL objects.

  3. Use the resulting EDSL objects as you would any other EDSL object, such as analyzing results or extending them with new survey questions for the agents.

Example

Here we demonstrate these methods using the some results from a survey about shopping preferences, stored in a CSV file. The file contains a respondent ‘UUID’ column and 5 columns of survey responses. The first row contains the column names:

What is your favorite store?,What is your preferred method of payment?,Rate your satisfaction with shopping options.,What is your preferred shopping day?,Do you have any suggestions for improvements in shopping options?
Walmart,Credit Card,4,Weekend,More frequent sales and discounts
Target,Debit Card,5,Weekday,Improve website navigation
Amazon,PayPal,3,Weekend,Offer free shipping
Costco,Cash,2,Weekend,Extend return policy
Local Boutique,Credit Card,5,Weekday,Add more product variety
Whole Foods,Debit Card,4,Weekend,Include more organic options
Best Buy,PayPal,3,Weekday,Enhance customer support
Trader Joe's,Cash,4,Weekend,Better parking facilities

Create a Conjure object

First, we create a Conjure object by passing the path to the file:

from edsl import Conjure

c = Conjure("my_survey.csv")

We can inspect some basic information about the new object:

c

Output:

InputDataCSV: datafile_name:'my_survey.csv' num_questions:5, num_agents:8

We can get some basic statistics about the questions:

c.question_statistics("preferred_method_payment")

Output:

QuestionStats(num_responses=8, num_unique_responses=4, missing=0, unique_responses=['Credit Card', 'Cash', 'PayPal', 'Debit Card'], frac_numerical=0.0, top_5=[('Credit Card', 2), ('Debit Card', 2), ('PayPal', 2), ('Cash', 2)], frac_obs_from_top_5=1.0)

Create an AgentList

We can use the to_agent_list() method to generate an AgentList object from the Conjure object:

agents = c.to_agent_list()

The AgentList is a list of dictionaries, where each dictionary represents an agent and contains (1) the individual agent’s traits and (2) a codebook for the original survey. The traits are a dictionary with keys representing the original column names in the file and values that are the agent’s data/responses to each question. The codebook is a dictionary mapping the new trait names to the original column names in the data file:

We can inspect the components of the agent list that was created and individual agents:

agents[0]

Output:

{
    "traits": {
        "favorite_store": "Walmart",
        "preferred_method_payment": "Credit Card",
        "rate_satisfaction_shoppin": 4,
        "preferred_shopping_day": "Weekend",
        "suggestions_improvements": "More frequent sales and discounts"
    },
    "codebook": {
        "favorite_store": "What is your favorite store?",
        "preferred_method_payment": "What is your preferred method of payment?",
        "rate_satisfaction_shoppin": "Rate your satisfaction with shopping options.",
        "preferred_shopping_day": "What is your preferred shopping day?",
        "suggestions_improvements": "Do you have any suggestions for improvements in shopping options?"
    }
}

Create a Survey

We can use the to_survey() method to generate a Survey object from the Conjure object:

survey = c.to_survey()

We can inspect the full survey object or individual components:

survey

Output:

{
    "questions": [
        {
            "question_name": "favorite_store",
            "question_text": "What is your favorite store?",
            "question_options": [
                "Target",
                "Local Boutique",
                "Walmart",
                "Trader Joe's",
                "Costco",
                "Amazon",
                "Best Buy",
                "Whole Foods"
            ],
            "question_type": "multiple_choice"
        },
        {
            "question_name": "preferred_method_payment",
            "question_text": "What is your preferred method of payment?",
            "question_options": [
                "Credit Card",
                "Cash",
                "PayPal",
                "Debit Card"
            ],
            "question_type": "multiple_choice"
        },
        {
            "question_name": "rate_satisfaction_shoppin",
            "question_text": "Rate your satisfaction with shopping options.",
            "question_options": [
                "2",
                "3",
                "4",
                "5"
            ],
            "question_type": "multiple_choice"
        },
        {
            "question_name": "preferred_shopping_day",
            "question_text": "What is your preferred shopping day?",
            "question_options": [
                "Weekend",
                "Weekday"
            ],
            "question_type": "multiple_choice"
        },
        {
            "question_name": "suggestions_improvements",
            "question_text": "Do you have any suggestions for improvements in shopping options?",
            "question_options": [
                "Add more product variety",
                "Enhance customer support",
                "More frequent sales and discounts",
                "Improve website navigation",
                "Extend return policy",
                "Include more organic options",
                "Offer free shipping",
                "Better parking facilities"
            ],
            "question_type": "multiple_choice"
        }
    ],
    "memory_plan": {
        "survey_question_names": [
            "favorite_store",
            "preferred_method_payment",
            "rate_satisfaction_shoppin",
            "preferred_shopping_day",
            "suggestions_improvements"
        ],
        "survey_question_texts": [
            "What is your favorite store?",
            "What is your preferred method of payment?",
            "Rate your satisfaction with shopping options.",
            "What is your preferred shopping day?",
            "Do you have any suggestions for improvements in shopping options?"
        ],
        "data": {}
    },
    "rule_collection": {
        "rules": [
            {
                "current_q": 0,
                "expression": "True",
                "next_q": 1,
                "priority": -1,
                "question_name_to_index": {
                    "favorite_store": 0
                },
                "before_rule": false,
                "edsl_version": "0.1.27",
                "edsl_class_name": "Rule"
            },
            {
                "current_q": 1,
                "expression": "True",
                "next_q": 2,
                "priority": -1,
                "question_name_to_index": {
                    "favorite_store": 0,
                    "preferred_method_payment": 1
                },
                "before_rule": false,
                "edsl_version": "0.1.27",
                "edsl_class_name": "Rule"
            },
            {
                "current_q": 2,
                "expression": "True",
                "next_q": 3,
                "priority": -1,
                "question_name_to_index": {
                    "favorite_store": 0,
                    "preferred_method_payment": 1,
                    "rate_satisfaction_shoppin": 2
                },
                "before_rule": false,
                "edsl_version": "0.1.27",
                "edsl_class_name": "Rule"
            },
            {
                "current_q": 3,
                "expression": "True",
                "next_q": 4,
                "priority": -1,
                "question_name_to_index": {
                    "favorite_store": 0,
                    "preferred_method_payment": 1,
                    "rate_satisfaction_shoppin": 2,
                    "preferred_shopping_day": 3
                },
                "before_rule": false,
                "edsl_version": "0.1.27",
                "edsl_class_name": "Rule"
            },
            {
                "current_q": 4,
                "expression": "True",
                "next_q": 5,
                "priority": -1,
                "question_name_to_index": {
                    "favorite_store": 0,
                    "preferred_method_payment": 1,
                    "rate_satisfaction_shoppin": 2,
                    "preferred_shopping_day": 3,
                    "suggestions_improvements": 4
                },
                "before_rule": false,
                "edsl_version": "0.1.27",
                "edsl_class_name": "Rule"
            }
        ],
        "num_questions": null
    },
    "question_groups": {}
}

Create Results

We can use the to_results() method to generate a Results object from the Conjure object:

results = c.to_results()

We can review a list the components of the results that were created:

results.columns

We can see that the columns of the original file have been stored as questions and answers in the results object:

['agent.agent_instruction',
'agent.agent_name',
'agent.favorite_store',
'agent.preferred_method_payment',
'agent.preferred_shopping_day',
'agent.rate_satisfaction_shoppin',
'agent.suggestions_improvements',
'answer.follow_up',
'iteration.iteration',
'model.frequency_penalty',
'model.logprobs',
'model.max_tokens',
'model.model',
'model.presence_penalty',
'model.temperature',
'model.top_logprobs',
'model.top_p',
'prompt.follow_up_system_prompt',
'prompt.follow_up_user_prompt',
'question_options.follow_up_question_options',
'question_text.follow_up_question_text',
'question_type.follow_up_question_type',
'raw_model_response.follow_up_raw_model_response',
'scenario.original_q']

Editing the “conjured” objects

We can use the rename() and rename_questions() methods to edit the components of the Conjure object. For example, we can change the question names that were generated:

c.rename_questions({"rate_satisfaction_shoppin": "shopping_satisfaction"})

Using your “conjured” EDSL objects

Once you have created an AgentList, Survey, or Results object from your Conjure object, you can use them as you would any other EDSL object.

Here we administer a new question to the agents that we created above, a follow-up to one of the original questions:

from edsl.questions import QuestionFreeText

q = QuestionFreeText(
    question_name = "more_store",
    question_text = "What do you love most about your favorite store?"
)

results = q.by(agents).run()

We can verify that the agent traits representing the original survey responses are components of the results (see the components with the agent. prefix):

results.columns

Output:

['agent.agent_instruction',
'agent.agent_name',
'agent.favorite_store',
'agent.preferred_method_payment',
'agent.preferred_shopping_day',
'agent.rate_satisfaction_shoppin',
'agent.suggestions_improvements',
'answer.more_store',
'iteration.iteration',
'model.frequency_penalty',
'model.logprobs',
'model.max_tokens',
'model.model',
'model.presence_penalty',
'model.temperature',
'model.top_logprobs',
'model.top_p',
'prompt.more_store_system_prompt',
'prompt.more_store_user_prompt',
'question_options.more_store_question_options',
'question_text.more_store_question_text',
'question_type.more_store_question_type',
'raw_model_response.more_store_raw_model_response']

We can inspect them together with the responses to the new question as usual:

results.select("favorite_store", "more_store").print(format="rich").print(format="rich", max_rows=3)

Output:

┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ agent           ┃ answer                                                                                        ┃
┃ .favorite_store ┃ .more_store                                                                                   ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Costco          │ What I love most about Costco is the bulk buying options which offer great value for money,   │
│                 │ the quality of their in-house brand Kirkland Signature, and the wide variety of products      │
│                 │ available under one roof. Additionally, the free samples and the food court make for a        │
│                 │ pleasant shopping experience.                                                                 │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Local Boutique  │ What I love most about my favorite local boutique is the unique selection of items that you   │
│                 │ can't find anywhere else. Each piece feels special and curated, and I appreciate the personal │
│                 │ touch that the store adds to the shopping experience. It's like discovering a treasure trove  │
│                 │ of fashionable gems every time I visit.                                                       │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Trader Joe's    │ What I love most about Trader Joe's is their unique selection of products that you can't find │
│                 │ anywhere else. The store offers a variety of organic and non-GMO options, which is important  │
│                 │ to me. I also appreciate the friendly and helpful staff who always make shopping there a      │
│                 │ pleasant experience. Plus, their prices are reasonable for the quality you get, making it a   │
│                 │ great value overall.                                                                          │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Whole Foods     │ What I love most about Whole Foods is their commitment to providing a wide range of           │
│                 │ high-quality, natural, and organic foods. The store's atmosphere is welcoming, and it offers  │
│                 │ a variety of sustainable and eco-friendly products that align with my values. Additionally,   │
│                 │ their fresh produce section is always stocked with a great selection of organic fruits and    │
│                 │ vegetables, which is very important to me.                                                    │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Amazon          │ What I love most about my favorite store, Amazon, is the vast selection of products           │
│                 │ available. I can find almost anything I need, from electronics to groceries, which is         │
│                 │ incredibly convenient. The user reviews and ratings help me make informed decisions, and the  │
│                 │ personalized recommendations often introduce me to items that I didn't even know I needed.    │
│                 │ Plus, the convenience of having everything delivered to my door is a huge plus.               │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Target          │ What I love most about Target is the wide variety of products they offer, from groceries to   │
│                 │ home goods, electronics, and clothing. I can usually find everything I need in one trip.      │
│                 │ Plus, the store layout is well-organized, which makes shopping efficient and enjoyable. Their │
│                 │ customer service is also generally very good, with helpful and friendly staff.                │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Best Buy        │ What I love most about Best Buy is their wide selection of electronics and gadgets. It's like │
│                 │ a one-stop-shop for all the latest tech, which means I can usually find whatever I'm looking  │
│                 │ for in one trip. Plus, they often have knowledgeable staff who can help answer my questions   │
│                 │ about the products.                                                                           │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Walmart         │ What I love most about Walmart is the convenience it offers with its wide range of products.  │
│                 │ From groceries to electronics, I can find almost everything I need in one place. The prices   │
│                 │ are also quite competitive, which is great for budget-conscious shoppers like me.             │
│                 │ Additionally, the store layout is usually well-organized, making it easy to find what I'm     │
│                 │ looking for. The fact that it's open late is a bonus, as it fits my busy schedule, especially │
│                 │ on weekends.                                                                                  │
└─────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────┘

We can also reference original questions as scenarios of new questions:

from edsl.questions import QuestionFreeText
from edsl import Scenario

q = QuestionFreeText(
    question_name = "follow_up",
    question_text = "Tell me more about your response to the question '{{ original_q }}'"
)
s = [Scenario({"original_q": q.question_text}) for q in survey.questions]

results = q.by(s).by(agents).run()

(results
.filter("agent_name == 'Agent_0'") # Filter results by any fields
.select("agent_name", "original_q", "follow_up") # Select components to inspect
.print(pretty_labels = {"original_q":"Original question", "follow_up":"Follow-up question"},
        format="rich")
)

Output:

┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ agent       ┃ scenario                                        ┃ answer                                          ┃
┃ .agent_name ┃ .original_q                                     ┃ .follow_up                                      ┃
┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Agent_0     │ What is your favorite store?                    │ My favorite store is Walmart because it offers  │
│             │                                                 │ a wide variety of products at competitive       │
│             │                                                 │ prices, all under one roof. It's convenient for │
│             │                                                 │ getting everything from groceries to            │
│             │                                                 │ electronics, and I appreciate their consistent  │
│             │                                                 │ stock and the availability of many brands.      │
│             │                                                 │ Plus, their store layout is generally           │
│             │                                                 │ shopper-friendly, making it easy to find what I │
│             │                                                 │ need.                                           │
├─────────────┼─────────────────────────────────────────────────┼─────────────────────────────────────────────────┤
│ Agent_0     │ What is your preferred method of payment?       │ My preferred method of payment is using a       │
│             │                                                 │ credit card. It's convenient, secure, and I can │
│             │                                                 │ track my expenses easily. Plus, I enjoy the     │
│             │                                                 │ benefits of reward points and the ability to    │
│             │                                                 │ handle larger purchases that I might not want   │
│             │                                                 │ to pay for all at once.                         │
├─────────────┼─────────────────────────────────────────────────┼─────────────────────────────────────────────────┤
│ Agent_0     │ Rate your satisfaction with shopping options.   │ I would rate my satisfaction with shopping      │
│             │                                                 │ options as fairly high, around a 4 out of 5.    │
│             │                                                 │ There's a good variety of products and I can    │
│             │                                                 │ usually find what I need, but there's always    │
│             │                                                 │ room for improvement, like having more frequent │
│             │                                                 │ sales and discounts to enhance the shopping     │
│             │                                                 │ experience.                                     │
├─────────────┼─────────────────────────────────────────────────┼─────────────────────────────────────────────────┤
│ Agent_0     │ What is your preferred shopping day?            │ My preferred shopping day is the weekend. I     │
│             │                                                 │ find that weekends are more convenient for me   │
│             │                                                 │ to browse through stores at a leisurely pace    │
│             │                                                 │ without the rush of weekday commitments. It's   │
│             │                                                 │ the time when I can take a moment to carefully  │
│             │                                                 │ select items I need, compare prices, and enjoy  │
│             │                                                 │ any in-store promotions that might be           │
│             │                                                 │ happening. Plus, it's a nice break from the     │
│             │                                                 │ weekly routine.                                 │
├─────────────┼─────────────────────────────────────────────────┼─────────────────────────────────────────────────┤
│ Agent_0     │ Do you have any suggestions for improvements in │ I think having more frequent sales and          │
│             │ shopping options?                               │ discounts would greatly improve the shopping    │
│             │                                                 │ experience. It would not only give customers    │
│             │                                                 │ like me more value for our money but also       │
│             │                                                 │ encourage us to shop more often. Additionally,  │
│             │                                                 │ these promotions could be a way to clear out    │
│             │                                                 │ inventory, making room for new and different    │
│             │                                                 │ products.                                       │
└─────────────┴─────────────────────────────────────────────────┴─────────────────────────────────────────────────┘

Conjure class

class edsl.conjure.Conjure.Conjure(datafile_name: str, *args, **kwargs)[source]
__init__(datafile_name: str, config: dict | None = None, naming_function: Callable | None = None, raw_data: List | None = None, question_names: List[str] | None = None, question_texts: List[str] | None = None, answer_codebook: Dict | None = None, question_types: List[str] | None = None, question_options: List | None = None, order_options=False, question_name_repair_func: Callable = None)[source]
classmethod example()[source]

InputData class

class edsl.conjure.InputData.InputDataABC(datafile_name: str, config: dict | None = None, naming_function: ~typing.Callable | None = <function sanitize_string>, raw_data: ~typing.List | None = None, binary: str | None = None, question_names: ~typing.List[str] | None = None, question_texts: ~typing.List[str] | None = None, answer_codebook: ~typing.Dict | None = None, question_types: ~typing.List[str] | None = None, question_options: ~typing.List | None = None, order_options=False, question_name_repair_func: ~typing.Callable = None)[source]

A class to represent the input data for a survey.

FRAC_NUMERICAL_THRESHOLD = 0.8[source]
MULTIPLE_CHOICE_OTHER_THRESHOLD = 0.5[source]
NUM_UNIQUE_THRESHOLD = 15[source]
OTHER_STRING = 'Other:'[source]
class QuestionStats(num_responses, num_unique_responses, missing, unique_responses, frac_numerical, top_5, frac_obs_from_top_5)[source]
count(value, /)[source]

Return number of occurrences of value.

frac_numerical[source]

Alias for field number 4

frac_obs_from_top_5[source]

Alias for field number 6

index(value, start=0, stop=9223372036854775807, /)[source]

Return first index of value.

Raises ValueError if the value is not present.

missing[source]

Alias for field number 2

num_responses[source]

Alias for field number 0

num_unique_responses[source]

Alias for field number 1

top_5[source]

Alias for field number 5

unique_responses[source]

Alias for field number 3

__init__(datafile_name: str, config: dict | None = None, naming_function: ~typing.Callable | None = <function sanitize_string>, raw_data: ~typing.List | None = None, binary: str | None = None, question_names: ~typing.List[str] | None = None, question_texts: ~typing.List[str] | None = None, answer_codebook: ~typing.Dict | None = None, question_types: ~typing.List[str] | None = None, question_options: ~typing.List | None = None, order_options=False, question_name_repair_func: ~typing.Callable = None)[source]

Initialize the InputData object.

Parameters:
  • datafile_name – The name of the file containing the data.

  • config – The configuration parameters for reading the data.

  • raw_data – The raw data in the form of a dictionary.

  • question_names – The names of the questions.

  • question_texts – The text of the questions.

  • answer_codebook – The codebook for the answers.

  • question_types – The types of the questions.

  • question_options – The options for the questions.

>>> id = InputDataABC.example(question_names = ['a','b'], answer_codebook = {'a': {'1':'yes', '2':'no'}, 'b': {'1':'yes', '2':'no'}})
>>> id = InputDataABC.example(question_names = ['a','b'], answer_codebook = {'a': {'1':'yes', '2':'no'}, 'c': {'1':'yes', '2':'no'}})
Traceback (most recent call last):
...
Exception: The keys of the answer_codebook must match the question_names.
agent(index) Agent[source]

Return an agent constructed from the data.

Parameters:

index – The index of the agent to construct.

>>> from edsl.conjure.InputData import InputDataABC
>>> id = InputDataABC.example()
>>> id.agent(0)
Agent(traits = {'morning': '1', 'feeling': '3'}, codebook = {'morning': 'how are you doing this morning?', 'feeling': 'how are you feeling?'})
property answer_codebook: dict[source]

Return the answer codebook. >>> id = InputDataABC.example(answer_codebook = {‘morning’:{‘1’:’hello’}}) >>> id.answer_codebook {‘morning’: {‘1’: ‘hello’}}

apply_codebook() None[source]

Apply the codebook to the raw data.

>>> id = InputDataABC.example()
>>> id.raw_data
[['1', '4'], ['3', '6']]
>>> id = InputDataABC.example(answer_codebook = {'morning':{'1':'hello'}})
>>> id.raw_data
[['hello', '4'], ['3', '6']]
compute_frac_numerical()[source]
compute_missing()[source]
compute_num_responses()[source]
compute_num_unique_responses()[source]
compute_unique_responses()[source]
drop(*question_names_to_drop) InputData[source]

Drop a question.

>>> id = InputDataABC.example()
>>> id.drop('morning').question_names
['feeling']
drop_missing(question_name)[source]

Drop missing values for a question.

>>> id = InputDataABC.example()
>>> id.num_observations
2
>>> id.raw_data[0][0] = 'missing'
>>> id.drop_missing('morning')
>>> id.num_observations
1
classmethod example(**kwargs) InputDataABC[source]
static filter_missing(responses) List[str][source]

Return a list of responses with missing values removed.

property frac_numerical: List[float][source]

The fraction of responses that are numerical for each question.

>>> from edsl.conjure.InputData import InputDataABC
>>> input_data = InputDataABC.example(raw_data = [[1,2,"Poop", 3]], question_texts = ['A question'])
>>> input_data.frac_numerical
[0.75]
property frac_obs_from_top_5[source]

The fraction of observations that are in the top 5 for each question.

frac_obs_from_top_k(k)[source]

Return the fraction of observations that are in the top k for each question.

>>> from edsl.conjure.InputData import InputDataABC
>>> input_data = InputDataABC.example(raw_data = [[1,1,1,1,1,1,1,1,2, 3]], question_names = ['a'])
>>> input_data.frac_obs_from_top_k(1)
[0.8]
classmethod from_dict(d: Dict)[source]
get_answer_codebook()[source]
abstract get_question_names() List[str][source]

Get the names of the questions.

>>> id = InputDataABC.example()
>>> id.get_question_names()
['morning', 'feeling']
abstract get_question_texts() List[str][source]

Get the text of the questions

>>> id = InputDataABC.example()
>>> id.get_question_texts()
['how are you doing this morning?', 'how are you feeling?']
abstract get_raw_data() List[List[str]][source]

Returns the responses by reading the datafile_name.

>>> id = InputDataABC.example()
>>> id.get_raw_data()
[['1', '4'], ['3', '6']]
keep(*question_names_to_keep, ignore_missing=False) InputDataABC[source]

Keep a question.

>>> id = InputDataABC.example()
>>> id.keep('morning').question_names
['morning']
property missing: List[int][source]

The number of observations that are missing.

>>> from edsl.conjure.InputData import InputDataABC
>>> input_data = InputDataABC.example(raw_data = [[1,2,Missing().value()]], question_texts = ['A question'])
>>> input_data.missing
[1]
modify_question_type(question_name: str, new_type: str, drop_options: bool = False, new_options: List[str] | None = None) InputData[source]

Modify the question type of a question. Checks to make sure the new type is valid.

>>> id = InputDataABC.example()
>>> id.modify_question_type('morning', 'numerical', drop_options = True).question_types
['numerical', 'multiple_choice']
>>> id = InputDataABC.example()
>>> id.modify_question_type('morning', 'poop')
Traceback (most recent call last):
...
ValueError: Question type poop is not available.
property names_to_texts: dict[source]

Return a dictionary of question names to question texts.

>>> id = InputDataABC.example()
>>> id.names_to_texts
{'morning': 'how are you doing this morning?', 'feeling': 'how are you feeling?'}
property num_observations[source]

Return the number of observations

>>> id = InputDataABC.example()
>>> id.num_observations
2
property num_responses: List[int][source]

Return the number of responses for each question.

>>> from edsl.conjure.InputData import InputDataABC
>>> id = InputDataABC.example()
>>> id.num_responses
[2, 2]
property num_unique_responses: List[int][source]

The number of unique responses for each question.

>>> from edsl.conjure.InputData import InputDataABC
>>> id = InputDataABC.example()
>>> id.num_unique_responses
[2, 2]
order_options() None[source]

Order the options for multiple choice questions using an LLM.

print()[source]
question_attributes = ['num_responses', 'num_unique_responses', 'missing', 'unique_responses', 'frac_numerical', 'top_5', 'frac_obs_from_top_5'][source]
property question_names: List[str][source]

Return a list of question names.

>>> id = InputDataABC.example()
>>> id.question_names
['morning', 'feeling']

We can pass question names instead:

>>> id = InputDataABC.example(question_names = ['a','b'])
>>> id.question_names
['a', 'b']
property question_options[source]
question_statistics(question_name: str) QuestionStats[source]

Return statistics for a question.

property question_texts: List[str][source]

Return a list of question texts.

>>> id = InputDataABC.example()
>>> id.question_texts
['how are you doing this morning?', 'how are you feeling?']
property question_types[source]
questions() Generator[QuestionBase | None, None, None][source]

Return a generator of Question objects.

property raw_data[source]
>>> id = InputDataABC.example()
>>> id.raw_data
[['1', '4'], ['3', '6']]
raw_question(index: int) RawQuestion[source]
raw_questions() Generator[RawQuestion, None, None][source]

Return a generator of RawQuestion objects.

rename(old_name, new_name, ignore_missing=False) InputData[source]

Rename a question.

>>> id = InputDataABC.example()
>>> id.rename('morning', 'evening').question_names
['evening', 'feeling']
rename_questions(rename_dict: Dict[str, str], ignore_missing=False) InputData[source]

Rename a question.

>>> id = InputDataABC.example()
>>> id.rename_questions({'morning': 'evening'}).question_names
['evening', 'feeling']
select(*question_names: List[str]) InputData[source]

Select a subset of the questions.

Parameters:

question_names – The names of the questions to select.

>>> id = InputDataABC.example()
>>> id.select('morning').question_names
['morning']
property texts_to_names[source]

Return a dictionary of question texts to question names.

>>> id = InputDataABC.example()
>>> id.texts_to_names
{'how are you doing this morning?': 'morning', 'how are you feeling?': 'feeling'}
to_agent_list(indices: List | None = None, sample_size: int = None, seed: str = 'edsl', remove_direct_question_answering_method: bool = True) AgentList[source]

Return an AgentList from the data.

Parameters:
  • indices – The indices of the agents to include.

  • sample_size – The number of agents to sample.

  • seed – The seed for the random number generator.

>>> from edsl.conjure.InputData import InputDataABC
>>> id = InputDataABC.example()
>>> al = id.to_agent_list()
>>> len(al) == id.num_observations
True
>>> al = id.to_agent_list(indices = [0, 1, 2])
Traceback (most recent call last):
...
ValueError: Index 2 is greater than the number of agents 2.
to_dataset() Dataset[source]
to_dict()[source]
to_results(indices: List | None = None, sample_size: int = None, seed: str = 'edsl', dryrun=False) Results | None[source]

Return the results of the survey.

Parameters:
  • indices – The indices of the agents to include.

  • sample_size – The number of agents to sample.

  • seed – The seed for the random number generator.

  • dryrun – If True, the survey will not be run, but the time to run it will be printed.

>>> from edsl.conjure.InputData import InputDataABC
>>> id = InputDataABC.example()
>>> r = id.to_results()
>>> len(r) == id.num_observations
True
to_scenario_list() ScenarioList[source]

Return a ScenarioList object from the raw response data.

>>> id = InputDataABC.example()
>>> s = id.to_scenario_list()
>>> type(s) == ScenarioList
True
>>> s
ScenarioList([Scenario({'morning': '1', 'feeling': '3'}), Scenario({'morning': '4', 'feeling': '6'})])
to_survey() Survey[source]
>>> id = InputDataABC.example()
>>> s = id.to_survey()
>>> type(s) == Survey
True
property top_5[source]

The top 5 responses for each question.

top_k(k: int) List[List[tuple]][source]
>>> from edsl.conjure.InputData import InputDataABC
>>> input_data = InputDataABC.example(raw_data = [[1,1,1,1,1,2]], question_texts = ['A question'])
>>> input_data.top_k(1)
[[(1, 5)]]
>>> input_data.top_k(2)
[[(1, 5), (2, 1)]]
property unique_responses: List[List[str]][source]

Return a list of unique responses for each question.

>>> from edsl.conjure.InputData import InputDataABC
>>> id = InputDataABC.example()
>>> id.unique_responses
[..., ...]
unique_responses_more_than_k(k, remove_missing=True) List[List[str]][source]

Return a list of unique responses that occur more than k times for each question.

>>> from edsl.conjure.InputData import InputDataABC
>>> id = InputDataABC.example()
>>> id.unique_responses_more_than_k(1)
[[...], [...]]