Build the estimate from actual batch costs

When a costing sheet allows $1.40 per kilogram and the dye floor later reports $1.71, the team may discover the gap only after the order has been quoted. To improve the next estimate, it needs to know which costs changed and whether the same conditions will apply again.

Regression analysis can help link chemical cost to recorded batch inputs. Although shade depth, liquor ratio, fabric weight and dye class may provide useful information, a fitted formula is only a starting point for a reliable estimate. It must predict suitable new batches well enough for its intended use.

The nine illustrative batches in this guide demonstrate how a model can fit its own data closely while leaving considerable uncertainty around its individual coefficients. Keep that distinction in view when deciding whether a model is ready for costing.

Define the cost per kilogram before fitting anything

Use one clear cost scope for every batch, avoiding inconsistencies such as including steam in some records when the intended outcome is chemical cost. State whether the figures include pretreatment, dyeing, washing, finishing and later additions. Water, energy, labour and overhead need separate treatment unless the model expressly includes them.

A basic calculation is:

Chemical cost per kg = Total cost of chemicals used for the batch ÷ Fabric mass on the agreed basis

Build the numerator from actual quantities and the chosen unit prices. Reconcile returns, unused prepared solution and recorded additions to avoid counting chemicals twice, and use the same fabric-mass basis for every batch denominator.

For example, $550 of chemicals on a 300 kg batch gives $1.8333/kg, whereas dividing the same cost by 330 kg of wet fabric gives $1.6667/kg. Keep moisture and mass conventions clear in the source record because the lower figure reflects a changed denominator rather than a saving.

Choose how prices will be handled, recognising that historical purchase prices describe what each batch cost at the time it was produced. Repricing recorded quantities at a common current price list helps separate process use from price changes. Keep these views distinct and label the price date.

Choose inputs that make process sense

Shade depth is often recorded as dye dose on fabric weight, or percentage owf. At the same product price, a 3% dose uses three times as much dye as a 1% dose. It does not make the full recipe three times as costly, because other products and additions have different dosing rules.

The shade percentage alone may hide differences in the dye mix when recipes with the same total dose use products at different prices. Record the relevant recipe or product family when that difference matters. CottonWorks' textile dyeing guide provides background on dye classes and their links to fibres and processes.

Because liquor ratio affects the amount of bath liquid, products dosed per litre behave differently from products dosed on fabric weight. Check the liquor ratio and dosing guide before treating these inputs as interchangeable.

GSM may stand in for fabric construction, loading or process differences in a historical dataset. By itself, it does not change a fixed percentage owf into a different chemical cost per kilogram. Include it only with a clear reason and enough data to assess its value.

Record fibre, machine, process route and rework where relevant, since their effects become difficult to separate when each dye class always follows a different route. A dye-class coefficient cannot separate those causes on its own.

Understand what the regression estimates

Multiple linear regression predicts one outcome from several inputs, using chemical cost per kilogram as the outcome in this example. The model adds an intercept and a contribution from each recorded input:

Predicted cost = Intercept + b1 × Shade depth + b2 × Liquor ratio + b3 × (GSM/10) + b4 × Dye class

Each coefficient is fitted from the batch records. Ordinary least squares chooses the coefficients that minimise the sum of squared differences between observed and fitted costs. NIST's least-squares guide explains this model structure.

A coefficient describes an association after allowing for the other included inputs, without proving what would happen if a process engineer changed that input. Missing factors, shared patterns and chance can all affect the result.

Code categories with indicators rather than an invented numeric scale, using 0 for the reference class and 1 for the other when there are two dye classes. With an intercept and three classes, use two indicator columns. Coding reactive, disperse and vat as 1, 2 and 3 would impose a spacing that has no sound basis here.

Prepare a usable batch table

Keep one row for each batch on the defined basis, separating identifiers from model inputs so that a batch number is not accidentally treated as a predictor. Retain the original records and document any corrections.

Check missing values, units and duplicate rows before fitting. Shade depth of 2% is entered as 2 in this example, not 0.02. Liquor ratio 1:7 is entered as the numeric denominator 7. Fabric GSM is divided by 10 for the model, so 190 GSM becomes 19.

Flag re-dyes and dosing errors, but do not delete a valid costly batch simply because it weakens the fit. Decide whether the model is meant to cover normal batches, batches with rework, or both. The reactive dyeing RFT guide explains why later additions need their own cost trail.

The following illustrative records contain reactive and disperse routes that may differ in fibres, equipment and other unrecorded ways. These process differences limit the records to demonstrating the calculation, rather than providing a cost database transferable to another mill.

Batch

Shade depth, % owf

Liquor-ratio denominator

GSM

Dye class

Cost, USD/kg

1

0.8

6

160

0

1.22

2

1.5

6

180

0

1.41

3

2.2

8

200

0

1.68

4

0.5

5

140

0

1.08

5

3.0

8

220

0

1.94

6

1.0

10

160

1

1.55

7

2.5

6

200

0

1.79

8

1.8

10

180

1

1.98

9

0.3

5

140

0

0.97

Dye class 0 means reactive and 1 means disperse, while the numerical liquor-ratio entry 6 represents 1:6 and follows the same convention as the other ratios. Keep those definitions visible wherever the data is copied.

Fit the model and check the output order

In Excel, place the six table columns in A:F, with data in rows 2:10. Create a separate input block H:K in the order shade depth, liquor-ratio denominator, GSM/10 and dye class. Keep the cost outcome in F.

One formula for the fitted statistics is:

=LINEST(F2:F10,H2:K10,TRUE,TRUE)

The first TRUE keeps an intercept, and the second requests extra statistics. Microsoft's LINEST documentation explains the returned array. Label the coefficients before using them in a costing formula because they appear in reverse input-column order, followed by the intercept.

Use the array-entry method supported by the installed Excel version, or fit the same model with a suitable desktop regression tool. Whichever route is used, retain the input order, raw data and output together. Do not assume that a copied coefficient belongs to the nearest heading.

For these exact nine rows, ordinary least squares with an intercept gives:

Term

Coefficient

Two-sided p-value

Intercept

0.952416

0.303

Shade depth, per percentage point

0.374049

0.112

Liquor-ratio denominator, per unit

−0.012785

0.786

GSM, per 10 units

−0.000436

0.995

Disperse indicator, versus reactive

0.424183

0.090

Coefficients are rounded to six decimals. The calculation uses four predictors plus one intercept, leaving 9 − 5 = 4 residual degrees of freedom. The p-values use the usual t tests under a correctly specified model with independent, normally distributed errors of equal variance.

These assumptions concern the model errors rather than the distributions of the input columns, and nine observations provide little evidence for verifying them in practice.

Read a high R-squared with care

The fitted model has R-squared 0.987695 and adjusted R-squared 0.975389. Those numbers describe the fit to these nine records without establishing that future recipe costs will be predicted with 98.77% accuracy.

With an intercept and the same fitted sample, ordinary R-squared cannot fall when extra predictors are added. Although adjusted R-squared penalises additional terms, it remains a training-data measure and does not provide a universal 0.75 pass mark for costing models.

Dyehouse recipe-cost forecasting workspace

None of the four predictor p-values is below 0.05, a result that can coexist with high overall fit when a small dataset contains closely related inputs. It does not prove that all the inputs are useless, nor that the formula is ready for quotes.

A p-value is evidence against a specified zero-coefficient hypothesis under the model assumptions. It is not the probability that the coefficient is true or a measure of commercial importance. Consider effect size, uncertainty and new-batch errors together. Forecasting: Principles and Practice discusses regression assessment and the distinction between association and causation.

Calculate a cost for a new set of inputs

Consider a reactive recipe with shade depth 2.0%, liquor ratio 1:7 and GSM 190. Its model inputs are 2, 7, 19 and 0.

Using the displayed rounded coefficients:

Predicted cost = 0.952416 + (0.374049 × 2) − (0.012785 × 7) − (0.000436 × 19) + (0.424183 × 0)

= 0.952416 + 0.748098 − 0.089495 − 0.008284

= $1.602735/kg

Using the unrounded fitted coefficients gives $1.602729/kg, or about $1.60/kg. Keep full precision in the worksheet, then round the reported estimate to a sensible level.

The negative liquor-ratio coefficient needs particular attention because it must not be interpreted as an instruction to increase liquor ratio to save chemicals. Review the process and input relationships before interpreting the sign, since this small, mixed dataset cannot support that causal claim.

The uncertain GSM coefficient is close to zero in this fit, but it does not establish that fabric construction never matters. It shows what this limited model estimated from these particular rows.

Show uncertainty around the point estimate

A single predicted cost hides two sources of uncertainty: uncertainty in the fitted mean and the variation of an individual new batch around that mean. A prediction interval for a new batch includes both, so it is wider than the confidence interval for the mean.

For the stated example inputs, the conventional 95% intervals from the unrounded fit are:

Result

Estimate or interval, USD/kg

Predicted mean cost

1.6027

Confidence interval for mean cost

1.5230 to 1.6825

Prediction interval for one new batch

1.4236 to 1.7819

These ranges require the same normal-error, equal-variance and independence assumptions as the t tests, together with a model that applies to the new batch. They are model-based teaching results, not a demonstrated service level from a working mill.

Statsmodels' prediction documentation distinguishes results for the mean from those for new observations. Whichever software is used, identify the reported interval before interpreting it, since a narrow mean interval cannot represent the range for one future batch.

The interval also does not cover every future price or process change. If a new dye price, machine or route falls outside the model's basis, the uncertainty calculation may understate the practical risk.

Inspect residuals and influential batches

A residual is actual cost minus fitted cost. For batch 1, the fitted value is about $1.1680/kg against an actual $1.22/kg, leaving a residual of about +$0.0520/kg. A positive value means the model underpredicted that batch.

Plot residuals against fitted cost, each main input and batch date. A curve can suggest that a straight-line term misses a pattern. A wider spread at high cost may conflict with equal variance. A run of positive errors after a price change may show that the cost basis has moved.

NIST's residual guidance explains why these checks matter. Because plots from a small sample can be hard to interpret, the absence of an obvious pattern should not be taken as confirmation that every model assumption holds.

For batches that strongly influence the fit, verify the records and compare fitted results with and without them as a diagnostic check. If a valid batch belongs to the intended operating scope, do not remove it just to improve R-squared. If it belongs to a different process, justify that separation using the process definition.

Test prediction on records the model has not used

The nine-row model has a mean absolute fitted error of about $0.0320/kg. That average absolute residual describes errors on the records used to estimate the coefficients, rather than providing an independent accuracy test.

As a further illustration, fit the same model nine times, leaving one batch out each time and predicting its cost from the other eight. The mean absolute error becomes about $0.0707/kg, more than twice the fitted error. This leave-one-out calculation exposes some sensitivity to the tiny dataset.

It still does not reproduce forecasting future batches, especially if prices or processes change with time. For that purpose, train on earlier records and test on later ones, using only information available at the quote date. The forecasting evaluation chapter explains time-ordered validation.

Keep related records together where needed, since splitting a batch's near-duplicate entries between training and test sets can exaggerate the apparent accuracy. Do not use a final addition amount as a predictor for a quote if that amount will be unknown when the quote is prepared.

Compare the model with a useful simple baseline, such as the current rate card or a recent average for the same route. Report absolute error, bias and large misses on the same held-out batches. Choose the model for the planning result it improves, not the number of terms it contains.

Separate a price revision from a process change

Consider a separate illustrative 300 kg batch that uses 10 kg of one dye. At $20 per kilogram of dye, that product costs $200. If all other chemicals cost $300, total chemical cost is $500, or $1.6667 per kilogram of fabric.

If the dye price rises to $24 while quantities stay unchanged, the dye costs $240 and the batch total becomes $540, equivalent to $1.80/kg. The increase of $0.1333/kg comes entirely from price in this example. It does not show that the process used more dye or that shade depth became less efficient.

Repricing the quantities gives a direct explanation that a broad historical regression may miss. It also shows why a single surcharge may be unsuitable across recipes: a recipe using less of that product has less exposure to its price rise. Keep the recipe quantities available alongside the fitted model, especially when prices move sharply.

If quantities also changed, calculate the price and usage effects on a stated basis before assigning the gap to the model. That check can reveal a data problem, a valid process change or a missing cost driver.

Review coverage, prices and readiness for use

Check the combinations of inputs as well as their individual ranges, since a recipe may combine shade, machine and route in a way absent from the training data. Such a prediction needs a manual process review.

An illustrative navy rate card may charge $1.65/kg while two recorded routes cost $1.89 and $1.58/kg. Their $0.31 difference is about 19.6% of $1.58. The spread deserves investigation, but it cannot be assigned to liquor ratio without checking the other differences. These figures are an example, not a verified mill study.

Although twenty completed batches can provide a starting point, additional records help only when they add reliable, relevant information; no fixed count automatically approves a four-input model. Coverage, repeated routes, price variation and the required forecast accuracy determine what evidence is needed.

As new results arrive, compare predictions with actual costs before refitting. Separate price movement from changes in chemical use where possible. Keep the earlier model and its test results so a new fit can be judged fairly. The manufacturing analytics guide explains the value of linking source records to decisions.

A useful costing model begins with a clear cost definition and ends with checked predictions on suitable new work. Preserve process judgement in the release decision. Regression can make an estimate easier to explain, but sound batch data and ongoing comparison with actual cost are what make it useful.

Prediction models need the same discipline as forecasts, so see forecast accuracy with MAE and WAPE, exponential smoothing for demand planning, vat dyeing and nylon acid dyeing.

References

  1. CottonWorks: Textile Dyeing.

  2. NIST: Linear Least Squares Regression.

  3. Microsoft: LINEST Function.

  4. Hyndman and Athanasopoulos: Time Series Regression Models.

  5. Statsmodels: OLS Prediction Results.

  6. NIST: Checking Model Residuals.

  7. Hyndman and Athanasopoulos: The Forecaster's Toolbox.