Write a SQL query that converts each study's odds ratio to Cohen's d with the log-odds scaling constant 0.5513, rounded to four decimals and sorted by study. It tests use of the natural logarithm, numeric rounding in PostgreSQL, and how effect sizes move between the odds ratio and standardized mean difference scales.
The `study_estimates` table has one row per study with `study_id` and `odds_ratio`. Convert each odds ratio to Cohen's d using $d = \ln(\text{odds ratio}) \times 0.5513$. Return one row per study with `study_id`, `odds_ratio` and `cohens_d` rounded to 4 decimals.
```hint Which logarithm
Check which base each PostgreSQL log function uses before you pick one.
```
### Input Table(s)
Table `study_estimates` (primary key `study_id`):
| Column | Type | Meaning |
|---|---|---|
| `study_id` | INT | Study identifier |
| `odds_ratio` | NUMERIC(8,2) | Odds ratio reported by the study |
### Output Contract
One row per study with these columns, in this order:
| Column | Definition | Rounding |
|---|---|---|
| `study_id` | From the input | none |
| `odds_ratio` | From the input, unchanged | none |
| `cohens_d` | `ln(odds_ratio) * 0.5513` | 4 decimals |
Sort the rows by `study_id` ascending.
### Example
Input `study_estimates`:
| study_id | odds_ratio |
|---|---|
| 894 | 2.95 |
| 826 | 0.92 |
| 577 | 5.83 |
| 535 | 1.10 |
Expected output:
| study_id | odds_ratio | cohens_d |
|---|---|---|
| 535 | 1.10 | 0.0525 |
| 577 | 5.83 | 0.9720 |
| 826 | 0.92 | -0.0460 |
| 894 | 2.95 | 0.5964 |
For study 894, ln(2.95) ≈ 1.0818 and 1.0818 × 0.5513 ≈ 0.5964. Study 826 has an odds ratio below 1, so its log and its d are negative: ln(0.92) ≈ -0.0834, which gives -0.0460.
### Constraints and Clarifications
- `study_id` is unique.
- `odds_ratio` is positive and never NULL.
- Use the constant 0.5513 as given. It is $\sqrt{3}/\pi$ rounded to four decimals.
- An odds ratio of exactly 1 maps to a d of 0.
Overview: Write a SQL query that converts each study's odds ratio to Cohen's d with the log-odds scaling constant 0.5513, rounded to four decimals and sorted by study. It tests use of the natural logarithm, numeric rounding in PostgreSQL, and how effect sizes move between the odds ratio and standardized mean difference scales.
The study_estimates table has one row per study with study_id and odds_ratio. Convert each odds ratio to Cohen's d using d=ln(odds ratio)×0.5513. Return one row per study with study_id, odds_ratio and cohens_d rounded to 4 decimals.
Input Table(s)
Table study_estimates (primary key study_id):
Column
Type
Meaning
study_id
INT
Study identifier
odds_ratio
NUMERIC(8,2)
Odds ratio reported by the study
Output Contract
One row per study with these columns, in this order:
Column
Definition
Rounding
study_id
From the input
none
odds_ratio
From the input, unchanged
none
cohens_d
ln(odds_ratio) * 0.5513
4 decimals
Sort the rows by study_id ascending.
Example
Input study_estimates:
study_id
odds_ratio
894
2.95
826
0.92
577
5.83
535
1.10
Expected output:
study_id
odds_ratio
cohens_d
535
1.10
0.0525
577
5.83
0.9720
826
0.92
-0.0460
894
2.95
0.5964
For study 894, ln(2.95) ≈ 1.0818 and 1.0818 × 0.5513 ≈ 0.5964. Study 826 has an odds ratio below 1, so its log and its d are negative: ln(0.92) ≈ -0.0834, which gives -0.0460.
Constraints and Clarifications
study_id
is unique.
odds_ratio
is positive and never NULL.
Use the constant 0.5513 as given. It is
3/π
rounded to four decimals.