Skip to main content

Grouped Analysis

Analyze each group separately with GROUP BY.

Use Case

Fit separate models for each product, region, or customer segment.

Basic Pattern

SELECT
product_id,
result.coefficients[1] as intercept,
result.coefficients[2] as price_effect,
result.r_squared,
result.rmse
FROM sales_data
GROUP BY product_id
APPLY anofox_statistics_ols_agg(demand, ARRAY[price]);

Complete Example

Marketing ROI by campaign:

SELECT
campaign_id,
result.coefficients[2] as roi,
result.p_value[2] as p_val,
result.r_squared
FROM marketing_data
GROUP BY campaign_id
APPLY anofox_statistics_ols_agg(
revenue,
ARRAY[marketing_spend]
)
WHERE result.p_value[2] < 0.05
ORDER BY roi DESC;

Next Steps

🍪 Cookie Settings