Skip to main content
deleted 3 characters in body
Source Link
ubpdqn
  • 65k
  • 3
  • 65
  • 154
rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[#] & /@ dn[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x, z}, 
      "Edited"}
  ]
rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[#] & /@ dn[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x, z}, 
      "Edited"}
  ]
rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[#] & /@ dn[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x}, 
      "Edited"}
  ]
deleted 4 characters in body
Source Link
ubpdqn
  • 65k
  • 3
  • 65
  • 154

EDIT Revision

Revision with only one pass of DayName on data:

rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[DayName[#]]f[#] & /@ d[[Alldn[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x, z}, 
      "Edited"}
  ]

EDIT Revision with only one pass of DayName on data:

rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[DayName[#]] & /@ d[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x, z}, 
      "Edited"}
  ]

EDIT

Revision with only one pass of DayName on data:

rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[#] & /@ dn[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x, z}, 
      "Edited"}
  ]
added 596 characters in body
Source Link
ubpdqn
  • 65k
  • 3
  • 65
  • 154

This post is motivating and based on the original post which involved defining control limits. In the following I have not merely used the sample mean by day as the replacement mean (for convenience,this is not what was posted but could be adapted ). In the small samples (n=1), StandardDeviation will not work, hence the first line. I agree with comments re: DayName.

EDIT Revision with only one pass of DayName on data:

rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[DayName[#]] & /@ d[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x, z}, 
      "Edited"}
  ]

This post is motivating and based on the original post which involved defining control limits. In the following I have not merely used the sample mean by day as the replacement mean (for convenience,this is not what was posted but could be adapted ). In the small samples (n=1), StandardDeviation will not work, hence the first line. I agree with comments re: DayName.

This post is motivating and based on the original post which involved defining control limits. In the following I have merely used the sample mean by day as the replacement mean (for convenience,this is not what was posted but could be adapted ). In the small samples (n=1), StandardDeviation will not work, hence the first line. I agree with comments re: DayName.

EDIT Revision with only one pass of DayName on data:

rout[d_, l_, u_] := Module[{dn, lmt, h, f, g, result},
  dn = {DayName[#1], #1, ##2} & @@@ d;
  lmt = {First@#1, Mean@#3 - l sd[#3], Mean@#3 + u sd[#3], 
      Mean[#3]} & @@@ (Transpose /@ GatherBy[dn, #[[1]] &]);
  (h[#1] := #4) & @@@ lmt;
  (f[#1] = Function[x, #2 < x < #3]) & @@@ lmt;
  g = MapThread[#1@#2 &, {(f[DayName[#]] & /@ d[[All, 1]]), 
     d[[All, 2]]}];
  result = 
   Thread[{dn, g}] /. {{x_, y_, z_}, False} :> {{x, y, h@x, z}, 
      "Edited"}
  ]
Source Link
ubpdqn
  • 65k
  • 3
  • 65
  • 154
Loading
Post Made Community Wiki by ubpdqn