Create a DataFrame — SCIA - Single Case Intervention Analysis with Python

Skip to main content
`Ctrl`+`K`

# Create a DataFrame

The `create_scd` function allows you to create a structured DataFrame for single-case data analysis. It is designed to handle phase-based measurements and can include additional variables.

## What Does `create_scd` Do?

The `create_scd` function creates a single-case experimental design (SCED) DataFrame. It requires at least `values`, which represent the recorded data. Phases can be defined either using `phase_starts` (which specifies where each phase begins) or `phase_design` (which specifies how long each phase lasts).

### Required Arguments:

- `values`: The primary data for your experiment (must be provided).

### Optional Arguments:

- `phase_starts`: Define where each phase begins (e.g., `{"A": 1, "B": 5}`).

- `phase_design`: Define how many measurements belong to each phase (e.g., `{"A": 4, "B": 6}`).

- `mt`: A list of measurement time points (optional).

- Extra variables (e.g., `teacher`, `hour`) can be included.

If no phase information is given, an error will be raised.

    import scia as sc

    📖 scia 1.101.0.dev6 - For Documentation, visit: https://ahsankhodami.github.io/scia/intro.html

### Example 1: Defining Phases with `phase_starts`

To create a simple dataset where phases are specified by their starting points:

    df = sc.create_scd(
        values=[2,2,4,5,8,7,6,9,8,7],
        phase_starts={"A": 1, "B": 5}
    )
    print(df)

       values  mt phase
    0       2   1     A
    1       2   2     A
    2       4   3     A
    3       5   4     A
    4       8   5     B
    5       7   6     B
    6       6   7     B
    7       9   8     B
    8       8   9     B
    9       7  10     B

### Example 2: Using `phase_design`

Here, phases are defined by specifying how many measurements belong to each phase:

    df = sc.create_scd(
        values=[2,2,4,5,8,7,6,9,8,7],
        mt=[1,2,3,6,8,9,11,12,16,18],
        phase_design={"A": 4, "B": 6}
    )
    print(df)

       values  mt phase
    0       2   1     A
    1       2   2     A
    2       4   3     A
    3       5   6     A
    4       8   8     B
    5       7   9     B
    6       6  11     B
    7       9  12     B
    8       8  16     B
    9       7  18     B

### Example 3: Including Additional Variables

Additional variables such as `teacher` and `hour` can be included:

    df = sc.create_scd(
        values={"A": [2,2,3,5], "B": [8,7,6,9,7,7]},
        teacher=[0,0,1,1,0,1,1,1,0,1],
        hour=[2,3,4,3,3,1,6,5,2,2]
    )
    print(df)

       teacher  hour  values  mt phase
    0        0     2       2   1     A
    1        0     3       2   2     A
    2        1     4       3   3     A
    3        1     3       5   4     A
    4        0     3       8   5     B
    5        1     1       7   6     B
    6        1     6       6   7     B
    7        1     5       9   8     B
    8        0     2       7   9     B
    9        1     2       7  10     B