# Robust_refinement_xye

Description: Robust refinements in topas

Contributed by: Kevin H. Stone, Saul H. Lapidus and Peter W. Stephens

Reference: J. Appl. Cryst. (2009). 42, 385–391; “Implementation and use of robust refinement in powder diffraction in the presence of impurities”

```macro Robust_refinement_xye
{
/*Rescale peaks according to robust refinement algorithm*/

r_exp 4.390
prm test = Get(r_exp);
prm N = (1/test)^2;
prm !p0  =0.40007404;
prm !p1  =-2.5949286;
prm !p2  =4.3513542;
prm !p3  =-1.7400101;
prm !p4  =3.6140845 * 10^-1;
prm !p5  =-4.5247609 * 10^-2;
prm !p6  =3.5986364 * 10^-3;
prm !p7  =-1.8328008 * 10^-4;
prm !p8  =5.7937184 * 10^-6;
prm !p9  =-1.035303 * 10^-7;
prm !p10 =7.9903166 * 10^-10;
prm t = ((Yobs - Ycalc)/SigmaYobs);
prm testjohn = If( t < 0.8,
(1/Max(SigmaYobs^2, 1))*N,
If(t < 21, N*((((((((((p10*t + p9)*t + p8)*t + p7)
*t + p6)*t + p5)*t + p4)*t + p3)
*t + p2)*t + p1)*t +p0)/(Yobs - Ycalc)^2,
N*(2.0131 * Ln(t) + 3.9183)/(Yobs - Ycalc)^2));
weighting = If( t < 0.8,
(1/Max(SigmaYobs^2, 1))*N,
If(t < 21, N*((((((((((p10*t + p9)*t + p8)*t + p7)
*t + p6)*t + p5)*t + p4)*t + p3)
*t + p2)*t + p1)*t +p0)/(Yobs - Ycalc)^2,
N*(2.0131 * Ln(t) + 3.9183)/(Yobs - Ycalc)^2));
recal_weighting_on_iter
}```
```macro Robust_refinement_poisson
{
'Rescale peaks according to robust refinement algorithm
'N.B. changed SigmaYobs to Yobs^0.5
r_exp 4.390
prm test = Get(r_exp);
prm N = (1/test)^2;
prm !p0  =0.40007404;
prm !p1  =-2.5949286;
prm !p2  =4.3513542;
prm !p3  =-1.7400101;
prm !p4  =3.6140845 * 10^-1;
prm !p5  =-4.5247609 * 10^-2;
prm !p6  =3.5986364 * 10^-3;
prm !p7  =-1.8328008 * 10^-4;
prm !p8  =5.7937184 * 10^-6;
prm !p9  =-1.035303 * 10^-7;
prm !p10 =7.9903166 * 10^-10;
prm t = ((Yobs - Ycalc)/Yobs^0.5);
prm testjohn = If( t < 0.8,
(1/Max(Yobs, 1))*N,
If(t < 21, N*((((((((((p10*t + p9)*t + p8)*t + p7)
*t + p6)*t + p5)*t + p4)*t + p3)
*t + p2)*t + p1)*t +p0)/(Yobs - Ycalc)^2,
N*(2.0131 * Ln(t) + 3.9183)/(Yobs - Ycalc)^2));
weighting = If( t < 0.8,
(1/Max(Yobs, 1))*N,
If(t < 21, N*((((((((((p10*t + p9)*t + p8)*t + p7)
*t + p6)*t + p5)*t + p4)*t + p3)
*t + p2)*t + p1)*t +p0)/(Yobs - Ycalc)^2,
N*(2.0131 * Ln(t) + 3.9183)/(Yobs - Ycalc)^2));
recal_weighting_on_iter
}```