# Issue with TERR implementation of loess function

I'm getting some odd results when using loess in TERR, when using the surface="direct" option - I get very discontinuous predicted data that's clearly not right.

Example code showing differences when using "direct" vs "interpolate" options (and yes, I need to use "direct"!):

``````set.seed=1
x<-1:50
y<-100-x+ rnorm(50,0,6)
df <- data.frame(x=x, y=y)
predict(loess(df\$y~df\$x,span=1, surface="direct", subset=(df\$x%2==1)),df)
predict(loess(df\$y~df\$x,span=1, surface="interpolate", subset=(df\$x%2==1)),df)
``````

Output from TERR and R below - any suggestions to get TERR to behave more like R?

Thank you,

David

TERR 4.5.0.113:

> predict(loess(df\$y~df\$x,span=1, surface="direct", subset=(df\$x%2==1)),df)

[1] 98.57187 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729

[18] 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 32.85729 65.38608 65.02569 64.78231 64.60092 64.43585 64.27014 64.10285 63.93854 63.78231 63.63809

[35] 63.50817 63.39319 63.29234 63.20316 63.12086 63.03985 62.95433 62.85841 62.74635 62.61257 62.45191 62.25946 62.03066 61.76119 61.44699 61.08443

> predict(loess(df\$y~df\$x,span=1, surface="interpolate", subset=(df\$x%2==1)),df)

[1] 105.35098 103.65678 101.99018 100.34998  98.73495  97.14387  95.57552  94.03001  92.50887  91.01299  89.54326  88.10055  86.68576  85.29427  83.92327  82.57635

[17]  81.25713  79.96920  78.71617  77.50229  76.32691  75.18631  74.07676  72.99453  71.93590  70.93282  69.99887  69.10280  68.21333  67.29918  66.32908  65.32761

[33]  64.33898  63.36143  62.39316  61.43239  60.47734  59.53284  58.60263  57.68327  56.77131  55.86331  54.95584  54.04668  53.13735  52.22994  51.32655  50.42930

[49]  49.54028        NA

R 3.6.1:

> predict(loess(df\$y~df\$x,span=1, surface="direct", subset=(df\$x%2==1)),df)

1        2        3        4        5        6        7        8        9       10       11       12       13       14       15       16       17       18       19       20

94.95492 94.53116 94.07628 93.58968 93.07067 92.51863 91.93318 91.31408 90.66123 89.97467 89.25454 88.50107 87.71449 86.89511 86.04340 85.15991 84.24515 83.29945 82.32229 81.31248

21       22       23       24       25       26       27       28       29       30       31       32       33       34       35       36       37       38       39       40

80.26863 79.18714 78.05905 76.86565 75.58541 74.21825 72.90505 71.63266 70.38482 69.14937 67.91979 66.69268 65.46618 64.23966 63.01351 61.78867 60.56661 59.34875 58.13622 56.93008

41       42       43       44       45       46       47       48       49       50

55.73143 54.54125 53.36045 52.18973 51.02937 49.87953 48.74046 47.61246 46.49602 45.39165

> predict(loess(df\$y~df\$x,span=1, surface="interpolate", subset=(df\$x%2==1)),df)

1        2        3        4        5        6        7        8        9       10       11       12       13       14       15       16       17       18       19       20

94.95504 94.53160 94.07678 93.59006 93.07091 92.51879 91.93318 91.31293 90.65801 89.96956 89.24873 88.49666 87.71449 86.89860 86.04625 85.15996 84.24220 83.29548 82.32229 81.30240

21       22       23       24       25       26       27       28       29       30       31       32       33       34       35       36       37       38       39       40

80.22309 79.09804 77.94095 76.76551 75.58541 74.36539 73.08148 71.76432 70.44455 69.15283 67.91979 66.71266 65.48489 64.24643 63.00726 61.77733 60.56661 59.36440 58.15644 56.94740

41       42       43       44       45       46       47       48       49       50

55.74195 54.54474 53.36045 52.19271 51.03963 49.89760 48.76300 47.63220 46.50158       NA

## 1 Comment

Update: I've now tried this in TERR 5.0 and the issue looks to be fixed - would still be good to see this fix cascaded to 4.5 though.

[My code got mangled originally - replace the single "%" with "%%" in the predict statements]

David Dixon - Jul 24, 2019 - 12:26am ::