Seringkali, kita memiliki ide untuk bentuk fungsi untuk model dan kita perlu memilih parameter yang akan membuat fungsi model cocok untuk pengamatan. Proses pemilihan parameter untuk mencocokkan pengamatan disebutpemasangan model.

Sebagai ilustrasi, data dalam file “utilitas.csv” mencatat suhu rata-rata setiap bulan (dalam derajat F) serta penggunaan gas alam bulanan (dalam kaki kubik, ccf). Ada, seperti yang kita duga, hubungan yang kuat antara keduanya.

library(mosaicCalc)
## Loading required package: mosaicCore
## Loading required package: Deriv
## Loading required package: Ryacas
## 
## Attaching package: 'Ryacas'
## The following object is masked from 'package:stats':
## 
##     integrate
## The following objects are masked from 'package:base':
## 
##     %*%, diag, diag<-, lower.tri, upper.tri
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D
Utils <- read.csv("http://www.mosaic-web.org/go/datasets/utilities.csv")
Utils
##    month day year temp  kwh ccf thermsPerDay dur totalbill gasbill elecbill
## 1      2  24 2005   29  557 166          6.0  28    213.71  166.63    47.08
## 2      3  29 2005   31  772 179          5.5  33    239.85  117.05    62.80
## 3      1  27 2005   15  891 224          7.5  30    294.96  223.92    71.04
## 4     11  23 2004   43  860  82          2.8  29    160.26   88.51    71.75
## 5     12  28 2004   23 1160 208          6.0  35    317.47  224.18    93.29
## 6      9  26 2004   71  922  15          0.5  32    117.46   21.25    96.21
## 7      8  25 2004   67  841  15          0.5  29    111.08   21.72    89.36
## 8      7  27 2004   72  860   8          0.3  30    106.65   15.59    91.06
## 9      1  28 2004   15  594 242          8.1  30    262.81  216.89    47.37
## 10     6  27 2004   64  911  18          0.6  32    119.65   25.14    94.51
## 11     5  26 2004   58  742  35          1.2  29    109.38   39.40    69.98
## 12     4  27 2004   48  709  78          2.6  30    120.08   65.67    54.41
## 13     3  28 2004   35  510 144          4.7  31    166.51  124.18    42.33
## 14     2  26 2004   16  563 216          7.6  29    239.60  193.45    46.15
## 15    12  29 2003   25  725 204          5.9  35    225.73  168.93    56.80
## 16    11  24 2003   35  570 130          4.6  29    151.62  106.61    45.01
## 17    10  26 2003   53  927  48          1.5  31    127.37   45.28    82.09
## 18     9  25 2003   69  888  16          0.5  30    108.54   21.08    87.46
## 19     8  26 2003   75  869  14          0.5  29    108.04   19.56    89.12
## 20     7  28 2003   72  934  15          0.5  32    116.29   21.28    95.01
## 21     6  26 2003   67  722  18          0.6  29     99.52   24.46    75.06
## 22     4  28 2003   46  503 100          3.2  32    127.07   86.83    40.24
## 23     3  27 2003   29  648 153          5.3  29    226.92  176.02    50.90
## 24    12  29 2002   25 1032 190          5.5  35    217.42  140.49    76.93
## 25    11  24 2002   34  865 126          4.1  31    154.93   94.67    65.02
## 26    10  24 2002   47  790  69          2.4  29    122.51   55.74    66.77
## 27     9  25 2002   69  838  16          0.5  30     99.46   18.16    82.20
## 28     8  26 2002   72  812  15          0.5  29    101.39   17.56    83.83
## 29     7  28 2002   76  925  16          0.5  32    111.65   18.61    93.04
## 30     6  26 2002   69  496  23          0.8  29     76.43   23.42    53.01
## 31     5  28 2002   51  394  60          2.0  30     87.47   48.92    38.55
## 32     4  28 2002   45  449 106          3.3  32    106.04   70.34    35.70
## 33     3  27 2002   21  471 190          6.6  29    152.32  113.63    38.69
## 34    11  26 2001   48 1046  79          2.4  33    134.50   53.60    80.90
## 35     1  28 2002   23  581 210          6.6  32    174.45  127.86    46.59
## 36     2  26 2002   28  551 178          6.2  29    147.06  102.85    44.21
## 37     6  26 2001   70  160   1          0.1  10     31.55    3.42    17.43
## 38    10  24 2001   51  828  44          1.6  29    107.58   32.38    75.20
## 39     9  25 2001   64  865  20          0.7  30    105.91   20.17    85.74
## 40     7  26 2001   76  736   7          0.2  30     92.36   12.79    79.57
## 41    10  24 2000   54  778  37          1.3  29    107.50   41.19    66.31
## 42    11  26 2000   37  617 123          3.8  33    150.13  102.52    47.61
## 43    12  27 2000   11  586 235          7.7  31    254.23  210.87    46.59
## 44     8  26 2001   75  923  15          0.5  31    114.95   18.10    96.85
## 45     2  26 2000   24  521 228          8.0  29    177.48  134.65    42.83
## 46     9  25 2000   64  864  17          0.5  32    104.86   21.39    83.47
## 47    12  29 1999   26  892 194          5.5  36    173.65  112.72    68.25
## 48     1  28 2000   18  533 164          5.6  30    139.18   95.88    43.30
## 49     8  24 2000   72  789  13          0.4  29     96.47   17.66    78.81
## 50     7  26 2000   72  935   0          0.0  32    102.44    8.08    94.36
## 51     4  28 2000   45  638  74          2.2  34    100.33   47.33    53.00
## 52     6  24 2000   66  583  23          0.9  25     85.30   25.55    59.75
## 53     5  30 2000   60  700 129          4.1  32    153.32   89.87    63.45
## 54     3  25 2000   41  554  16          0.6  28     61.27   15.32    45.95
## 55     2  26 2003   17  580 224          7.8  29    232.41  187.05    45.36
## 56     5  28 2003   56  496  43          1.4  30     92.86   43.77    49.09
## 57     4  28 2005   54  444  61          2.0  30    103.34   64.99    38.35
## 58     5  26 2005   56  645  51          1.8  28    127.22   61.81    65.41
## 59     8  25 2005   74  845   9          0.3  29    120.53   18.16   102.37
## 60     9  26 2005   69  995  11          0.3  32    135.07   22.33   112.74
## 61     7  27 2005   78  862  11          0.4  30    116.72   19.96    96.76
## 62     6  27 2005   72  939  19          0.6  32    131.02   27.30   103.72
## 63    10  25 2005   56  965  32          1.1  29    150.62   55.74    94.88
## 64    12  28 2005   21  931 176          5.8  31    324.52  240.90    83.62
## 65    11  27 2005   41  926  99          3.1  33    212.49  153.24    84.75
## 66     1  29 2006   30  927 144          4.5  32    282.25  193.84    90.28
## 67     2  27 2006   22  876 161          5.6  29    289.91  198.11    91.80
## 68     3  28 2006   34  749 116          4.0  29    210.85  138.65    72.20
## 69     4  26 2006   53  428  52          1.8  29     96.87   55.00    41.87
## 70     5  25 2006   59  450  38          1.3  29     95.04   47.39    47.65
## 71     6  26 2006   74  694  10          0.3  32     98.48   19.19    79.32
## 72     7  26 2006   78  954   7          0.2  30    131.27   16.37   114.90
## 73     8  24 2006   77  957   6          0.2  29    134.96   15.88   119.30
## 74     9  25 2006   64 1027  15          0.5  32    156.51   25.74   130.77
## 75    11  26 2006   41  663 101          3.1  33    168.24  106.54    62.72
## 76    12  27 2006   30  720 140          4.5  31    229.40  159.08    70.32
## 77    10  24 2006   50  893  47          1.6  29    144.16   46.12    98.04
## 78     1  28 2007   24  897 168          5.3  32    267.72  178.16    89.97
## 79     2  26 2007   13  808 191          6.7  29    298.50  207.53    90.97
## 80     3  26 2007   38  724 101          3.6  29    192.67  118.78    73.89
## 81     4  26 2007   46  707  77          2.6  30    159.01   82.76    76.25
## 82     5  28 2007   65  442  18          0.6  32     86.54   32.98    53.56
## 83     6  26 2007   74  305   7          0.2  29     67.19   21.41    45.78
## 84     7  27 2007   76  839   9          0.3  30    135.73   22.87   112.99
## 85     8  26 2007   75  809   6          0.2  31    123.07   19.17   103.90
## 86     9  25 2007   68  812  13          0.4  30    117.82   24.54    98.90
## 87    10  24 2007   58  761  28          1.0  29    123.40   38.59    85.81
## 88    11  26 2007   41  767  98          3.0  33    181.53  104.52    77.01
## 89    12  27 2007   18  980 182          6.0  31    296.10  194.91   101.19
## 90     3  27 2008   28  752 139          4.7  30    245.27  167.30    77.97
## 91     2  26 2008   15  804 191          6.7  29    292.12  207.32    84.80
## 92     4  27 2008   45  623  79          2.6  31    160.69   97.11    63.58
## 93     8  25 2008   75  544  12          0.4  29    103.28   26.83    76.45
## 94     5  27 2008   55  410  29          1.0  30    105.50   52.15    53.35
## 95     6  25 2008   68  196   6          0.2  29     53.92   20.97    32.95
## 96     9  25 2008   67  746  16          0.5  31    124.82   29.77    95.05
## 97     7  27 2008   76  477  11          0.3  32     99.14   69.82    29.32
## 98    10  26 2008   55  801  32          1.1  31    134.30   41.74    92.56
## 99    11  24 2008   39  868  91          3.0  29    186.18   93.60    92.58
##                                                         notes
## 1                                                            
## 2                                                            
## 3                                                            
## 4                                                            
## 5                                                            
## 6                                                            
## 7                                                            
## 8                                                            
## 9                                                            
## 10                                                           
## 11                                                           
## 12                                                           
## 13                                                           
## 14                                                           
## 15                                                           
## 16                                                           
## 17                                                           
## 18                                                           
## 19                                                           
## 20                                                           
## 21                                                           
## 22                                                           
## 23                                                           
## 24                                                           
## 25                                                           
## 26                                                           
## 27                                                           
## 28                                                           
## 29                                                           
## 30                                                           
## 31                                                           
## 32                                                           
## 33                                                           
## 34                                                           
## 35                                                           
## 36                                                           
## 37                                 transfer back from England
## 38                                                           
## 39                                                           
## 40                                                           
## 41                                                           
## 42                                                           
## 43                                                           
## 44                                                           
## 45                                                           
## 46                                                           
## 47                                                           
## 48                                                           
## 49                                                           
## 50                                                           
## 51                                                           
## 52                                                           
## 53                                                           
## 54                                          bad meter reading
## 55                                                           
## 56                                                           
## 57                                                           
## 58                                                           
## 59                                                           
## 60                                                           
## 61 high efficiency gas furnace and gas water heater installed
## 62                                                           
## 63                                                           
## 64                                                           
## 65                                                           
## 66                                                           
## 67                                                           
## 68                                                           
## 69                                                           
## 70                                                           
## 71                               away for 10 days on vacation
## 72                                                           
## 73                                                           
## 74                                                           
## 75                                                           
## 76                                                           
## 77                                                           
## 78                                                           
## 79                                                           
## 80                                                           
## 81                                                           
## 82                                                           
## 83                                                           
## 84                                                           
## 85                                                           
## 86                              5.46 credit for "cost of gas"
## 87                                                           
## 88                                                           
## 89                                                           
## 90                                               housesitters
## 91                                               housesitters
## 92                                               housesitters
## 93                                                           
## 94                                               housesitters
## 95                                                empty house
## 96                                                           
## 97                                                empty house
## 98                                                           
## 99

data diatas adalah yang terdapat di file utilitas

gf_point(ccf ~ temp, data = Utils) %>%
  gf_labs(y = "Natural gas usage (ccf/month)", 
          x = "Average outdoor temperature (F)")

dan kita buat model dari data asli dari data yang penting dari variabel ccf dan temp

library(mosaic)
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
f <- fitModel(ccf ~ A * temp + B, data = Utils)
gf_point(ccf ~ temp, data = Utils) %>%
  slice_plot(f(temp) ~ temp)

dan kita bisa membuat model lain dari data diatas

f2 <- fitModel(
  ccf ~ A * temp + B + C *sqrt(temp),
  data = Utils)
gf_point(
  ccf ~ temp, data = Utils) %>%
  slice_plot(f2(temp) ~ temp)

dan membuat variabel error dari datasets diatas

Utils$fitmodel <- f(Utils$temp)
Utils$error <- (Utils$ccf-Utils$fitmodel)
Utils
##    month day year temp  kwh ccf thermsPerDay dur totalbill gasbill elecbill
## 1      2  24 2005   29  557 166          6.0  28    213.71  166.63    47.08
## 2      3  29 2005   31  772 179          5.5  33    239.85  117.05    62.80
## 3      1  27 2005   15  891 224          7.5  30    294.96  223.92    71.04
## 4     11  23 2004   43  860  82          2.8  29    160.26   88.51    71.75
## 5     12  28 2004   23 1160 208          6.0  35    317.47  224.18    93.29
## 6      9  26 2004   71  922  15          0.5  32    117.46   21.25    96.21
## 7      8  25 2004   67  841  15          0.5  29    111.08   21.72    89.36
## 8      7  27 2004   72  860   8          0.3  30    106.65   15.59    91.06
## 9      1  28 2004   15  594 242          8.1  30    262.81  216.89    47.37
## 10     6  27 2004   64  911  18          0.6  32    119.65   25.14    94.51
## 11     5  26 2004   58  742  35          1.2  29    109.38   39.40    69.98
## 12     4  27 2004   48  709  78          2.6  30    120.08   65.67    54.41
## 13     3  28 2004   35  510 144          4.7  31    166.51  124.18    42.33
## 14     2  26 2004   16  563 216          7.6  29    239.60  193.45    46.15
## 15    12  29 2003   25  725 204          5.9  35    225.73  168.93    56.80
## 16    11  24 2003   35  570 130          4.6  29    151.62  106.61    45.01
## 17    10  26 2003   53  927  48          1.5  31    127.37   45.28    82.09
## 18     9  25 2003   69  888  16          0.5  30    108.54   21.08    87.46
## 19     8  26 2003   75  869  14          0.5  29    108.04   19.56    89.12
## 20     7  28 2003   72  934  15          0.5  32    116.29   21.28    95.01
## 21     6  26 2003   67  722  18          0.6  29     99.52   24.46    75.06
## 22     4  28 2003   46  503 100          3.2  32    127.07   86.83    40.24
## 23     3  27 2003   29  648 153          5.3  29    226.92  176.02    50.90
## 24    12  29 2002   25 1032 190          5.5  35    217.42  140.49    76.93
## 25    11  24 2002   34  865 126          4.1  31    154.93   94.67    65.02
## 26    10  24 2002   47  790  69          2.4  29    122.51   55.74    66.77
## 27     9  25 2002   69  838  16          0.5  30     99.46   18.16    82.20
## 28     8  26 2002   72  812  15          0.5  29    101.39   17.56    83.83
## 29     7  28 2002   76  925  16          0.5  32    111.65   18.61    93.04
## 30     6  26 2002   69  496  23          0.8  29     76.43   23.42    53.01
## 31     5  28 2002   51  394  60          2.0  30     87.47   48.92    38.55
## 32     4  28 2002   45  449 106          3.3  32    106.04   70.34    35.70
## 33     3  27 2002   21  471 190          6.6  29    152.32  113.63    38.69
## 34    11  26 2001   48 1046  79          2.4  33    134.50   53.60    80.90
## 35     1  28 2002   23  581 210          6.6  32    174.45  127.86    46.59
## 36     2  26 2002   28  551 178          6.2  29    147.06  102.85    44.21
## 37     6  26 2001   70  160   1          0.1  10     31.55    3.42    17.43
## 38    10  24 2001   51  828  44          1.6  29    107.58   32.38    75.20
## 39     9  25 2001   64  865  20          0.7  30    105.91   20.17    85.74
## 40     7  26 2001   76  736   7          0.2  30     92.36   12.79    79.57
## 41    10  24 2000   54  778  37          1.3  29    107.50   41.19    66.31
## 42    11  26 2000   37  617 123          3.8  33    150.13  102.52    47.61
## 43    12  27 2000   11  586 235          7.7  31    254.23  210.87    46.59
## 44     8  26 2001   75  923  15          0.5  31    114.95   18.10    96.85
## 45     2  26 2000   24  521 228          8.0  29    177.48  134.65    42.83
## 46     9  25 2000   64  864  17          0.5  32    104.86   21.39    83.47
## 47    12  29 1999   26  892 194          5.5  36    173.65  112.72    68.25
## 48     1  28 2000   18  533 164          5.6  30    139.18   95.88    43.30
## 49     8  24 2000   72  789  13          0.4  29     96.47   17.66    78.81
## 50     7  26 2000   72  935   0          0.0  32    102.44    8.08    94.36
## 51     4  28 2000   45  638  74          2.2  34    100.33   47.33    53.00
## 52     6  24 2000   66  583  23          0.9  25     85.30   25.55    59.75
## 53     5  30 2000   60  700 129          4.1  32    153.32   89.87    63.45
## 54     3  25 2000   41  554  16          0.6  28     61.27   15.32    45.95
## 55     2  26 2003   17  580 224          7.8  29    232.41  187.05    45.36
## 56     5  28 2003   56  496  43          1.4  30     92.86   43.77    49.09
## 57     4  28 2005   54  444  61          2.0  30    103.34   64.99    38.35
## 58     5  26 2005   56  645  51          1.8  28    127.22   61.81    65.41
## 59     8  25 2005   74  845   9          0.3  29    120.53   18.16   102.37
## 60     9  26 2005   69  995  11          0.3  32    135.07   22.33   112.74
## 61     7  27 2005   78  862  11          0.4  30    116.72   19.96    96.76
## 62     6  27 2005   72  939  19          0.6  32    131.02   27.30   103.72
## 63    10  25 2005   56  965  32          1.1  29    150.62   55.74    94.88
## 64    12  28 2005   21  931 176          5.8  31    324.52  240.90    83.62
## 65    11  27 2005   41  926  99          3.1  33    212.49  153.24    84.75
## 66     1  29 2006   30  927 144          4.5  32    282.25  193.84    90.28
## 67     2  27 2006   22  876 161          5.6  29    289.91  198.11    91.80
## 68     3  28 2006   34  749 116          4.0  29    210.85  138.65    72.20
## 69     4  26 2006   53  428  52          1.8  29     96.87   55.00    41.87
## 70     5  25 2006   59  450  38          1.3  29     95.04   47.39    47.65
## 71     6  26 2006   74  694  10          0.3  32     98.48   19.19    79.32
## 72     7  26 2006   78  954   7          0.2  30    131.27   16.37   114.90
## 73     8  24 2006   77  957   6          0.2  29    134.96   15.88   119.30
## 74     9  25 2006   64 1027  15          0.5  32    156.51   25.74   130.77
## 75    11  26 2006   41  663 101          3.1  33    168.24  106.54    62.72
## 76    12  27 2006   30  720 140          4.5  31    229.40  159.08    70.32
## 77    10  24 2006   50  893  47          1.6  29    144.16   46.12    98.04
## 78     1  28 2007   24  897 168          5.3  32    267.72  178.16    89.97
## 79     2  26 2007   13  808 191          6.7  29    298.50  207.53    90.97
## 80     3  26 2007   38  724 101          3.6  29    192.67  118.78    73.89
## 81     4  26 2007   46  707  77          2.6  30    159.01   82.76    76.25
## 82     5  28 2007   65  442  18          0.6  32     86.54   32.98    53.56
## 83     6  26 2007   74  305   7          0.2  29     67.19   21.41    45.78
## 84     7  27 2007   76  839   9          0.3  30    135.73   22.87   112.99
## 85     8  26 2007   75  809   6          0.2  31    123.07   19.17   103.90
## 86     9  25 2007   68  812  13          0.4  30    117.82   24.54    98.90
## 87    10  24 2007   58  761  28          1.0  29    123.40   38.59    85.81
## 88    11  26 2007   41  767  98          3.0  33    181.53  104.52    77.01
## 89    12  27 2007   18  980 182          6.0  31    296.10  194.91   101.19
## 90     3  27 2008   28  752 139          4.7  30    245.27  167.30    77.97
## 91     2  26 2008   15  804 191          6.7  29    292.12  207.32    84.80
## 92     4  27 2008   45  623  79          2.6  31    160.69   97.11    63.58
## 93     8  25 2008   75  544  12          0.4  29    103.28   26.83    76.45
## 94     5  27 2008   55  410  29          1.0  30    105.50   52.15    53.35
## 95     6  25 2008   68  196   6          0.2  29     53.92   20.97    32.95
## 96     9  25 2008   67  746  16          0.5  31    124.82   29.77    95.05
## 97     7  27 2008   76  477  11          0.3  32     99.14   69.82    29.32
## 98    10  26 2008   55  801  32          1.1  31    134.30   41.74    92.56
## 99    11  24 2008   39  868  91          3.0  29    186.18   93.60    92.58
##                                                         notes   fitmodel
## 1                                                             152.634927
## 2                                                             145.706424
## 3                                                             201.134442
## 4                                                             104.135411
## 5                                                             173.420433
## 6                                                               7.136381
## 7                                                              20.993385
## 8                                                               3.672130
## 9                                                             201.134442
## 10                                                             31.386138
## 11                                                             52.171645
## 12                                                             86.814156
## 13                                                            131.849420
## 14                                                            197.670191
## 15                                                            166.491931
## 16                                                            131.849420
## 17                                                             69.492900
## 18                                                             14.064883
## 19                                                             -6.720624
## 20                                                              3.672130
## 21                                                             20.993385
## 22                                                             93.742658
## 23                                                            152.634927
## 24                                                            166.491931
## 25                                                            135.313671
## 26                                                             90.278407
## 27                                                             14.064883
## 28                                                              3.672130
## 29                                                            -10.184875
## 30                                                             14.064883
## 31                                                             76.421403
## 32                                                             97.206909
## 33                                                            180.348935
## 34                                                             86.814156
## 35                                                            173.420433
## 36                                                            156.099178
## 37                                 transfer back from England  10.600632
## 38                                                             76.421403
## 39                                                             31.386138
## 40                                                            -10.184875
## 41                                                             66.028649
## 42                                                            124.920918
## 43                                                            214.991446
## 44                                                             -6.720624
## 45                                                            169.956182
## 46                                                             31.386138
## 47                                                            163.027680
## 48                                                            190.741689
## 49                                                              3.672130
## 50                                                              3.672130
## 51                                                             97.206909
## 52                                                             24.457636
## 53                                                             45.243143
## 54                                          bad meter reading 111.063913
## 55                                                            194.205940
## 56                                                             59.100147
## 57                                                             66.028649
## 58                                                             59.100147
## 59                                                             -3.256372
## 60                                                             14.064883
## 61 high efficiency gas furnace and gas water heater installed -17.113377
## 62                                                              3.672130
## 63                                                             59.100147
## 64                                                            180.348935
## 65                                                            111.063913
## 66                                                            149.170675
## 67                                                            176.884684
## 68                                                            135.313671
## 69                                                             69.492900
## 70                                                             48.707394
## 71                               away for 10 days on vacation  -3.256372
## 72                                                            -17.113377
## 73                                                            -13.649126
## 74                                                             31.386138
## 75                                                            111.063913
## 76                                                            149.170675
## 77                                                             79.885654
## 78                                                            169.956182
## 79                                                            208.062944
## 80                                                            121.456667
## 81                                                             93.742658
## 82                                                             27.921887
## 83                                                             -3.256372
## 84                                                            -10.184875
## 85                                                             -6.720624
## 86                              5.46 credit for "cost of gas"  17.529134
## 87                                                             52.171645
## 88                                                            111.063913
## 89                                                            190.741689
## 90                                               housesitters 156.099178
## 91                                               housesitters 201.134442
## 92                                               housesitters  97.206909
## 93                                                             -6.720624
## 94                                               housesitters  62.564398
## 95                                                empty house  17.529134
## 96                                                             20.993385
## 97                                                empty house -10.184875
## 98                                                             62.564398
## 99                                                            117.992416
##          error
## 1   13.3650735
## 2   33.2935756
## 3   22.8655582
## 4  -22.1354113
## 5   34.5795669
## 6    7.8636192
## 7   -5.9933852
## 8    4.3278703
## 9   40.8655582
## 10 -13.3861384
## 11 -17.1716450
## 12  -8.8141559
## 13  12.1505800
## 14  18.3298093
## 15  37.5080691
## 16  -1.8494200
## 17 -21.4929004
## 18   1.9351170
## 19  20.7206235
## 20  11.3278703
## 21  -2.9933852
## 22   6.2573420
## 23   0.3650735
## 24  23.5080691
## 25  -9.3136711
## 26 -21.2784069
## 27   1.9351170
## 28  11.3278703
## 29  26.1848746
## 30   8.9351170
## 31 -16.4214026
## 32   8.7930909
## 33   9.6510648
## 34  -7.8141559
## 35  36.5795669
## 36  21.9008224
## 37  -9.6006319
## 38 -32.4214026
## 39 -11.3861384
## 40  17.1848746
## 41 -29.0286493
## 42  -1.9209178
## 43  20.0085539
## 44  21.7206235
## 45  58.0438180
## 46 -14.3861384
## 47  30.9723202
## 48 -26.7416885
## 49   9.3278703
## 50  -3.6721297
## 51 -23.2069091
## 52  -1.4576363
## 53  83.7568572
## 54 -95.0639135
## 55  29.7940604
## 56 -16.1001471
## 57  -5.0286493
## 58  -8.1001471
## 59  12.2563725
## 60  -3.0648830
## 61  28.1133768
## 62  15.3278703
## 63 -27.1001471
## 64  -4.3489352
## 65 -12.0639135
## 66  -5.1706755
## 67 -15.8846842
## 68 -19.3136711
## 69 -17.4929004
## 70 -10.7073939
## 71  13.2563725
## 72  24.1133768
## 73  19.6491257
## 74 -16.3861384
## 75 -10.0639135
## 76  -9.1706755
## 77 -32.8856537
## 78  -1.9561820
## 79 -17.0629440
## 80 -20.4566667
## 81 -16.7426580
## 82  -9.9218873
## 83  10.2563725
## 84  19.1848746
## 85  12.7206235
## 86  -4.5291341
## 87 -24.1716450
## 88 -13.0639135
## 89  -8.7416885
## 90 -17.0991776
## 91 -10.1344418
## 92 -18.2069091
## 93  18.7206235
## 94 -33.5643982
## 95 -11.5291341
## 96  -4.9933852
## 97  21.1848746
## 98 -30.5643982
## 99 -26.9924157

dan untuk mengurutkan nilai error dari yang terkecil sampai yang terbesar dengan menggunakan fungsi sort, decreasing bernilai False

r <- sort(Utils$error,decreasing = FALSE)
r
##  [1] -95.0639135 -33.5643982 -32.8856537 -32.4214026 -30.5643982 -29.0286493
##  [7] -27.1001471 -26.9924157 -26.7416885 -24.1716450 -23.2069091 -22.1354113
## [13] -21.4929004 -21.2784069 -20.4566667 -19.3136711 -18.2069091 -17.4929004
## [19] -17.1716450 -17.0991776 -17.0629440 -16.7426580 -16.4214026 -16.3861384
## [25] -16.1001471 -15.8846842 -14.3861384 -13.3861384 -13.0639135 -12.0639135
## [31] -11.5291341 -11.3861384 -10.7073939 -10.1344418 -10.0639135  -9.9218873
## [37]  -9.6006319  -9.3136711  -9.1706755  -8.8141559  -8.7416885  -8.1001471
## [43]  -7.8141559  -5.9933852  -5.1706755  -5.0286493  -4.9933852  -4.5291341
## [49]  -4.3489352  -3.6721297  -3.0648830  -2.9933852  -1.9561820  -1.9209178
## [55]  -1.8494200  -1.4576363   0.3650735   1.9351170   1.9351170   4.3278703
## [61]   6.2573420   7.8636192   8.7930909   8.9351170   9.3278703   9.6510648
## [67]  10.2563725  11.3278703  11.3278703  12.1505800  12.2563725  12.7206235
## [73]  13.2563725  13.3650735  15.3278703  17.1848746  18.3298093  18.7206235
## [79]  19.1848746  19.6491257  20.0085539  20.7206235  21.1848746  21.7206235
## [85]  21.9008224  22.8655582  23.5080691  24.1133768  26.1848746  28.1133768
## [91]  29.7940604  30.9723202  33.2935756  34.5795669  36.5795669  37.5080691
## [97]  40.8655582  58.0438180  83.7568572

dan untuk mengurutkan nilai error dari yang terbesar ke terkecil menggunakan sort dengan decreasing bernilai True

r <- sort(Utils$error,decreasing = TRUE)
r
##  [1]  83.7568572  58.0438180  40.8655582  37.5080691  36.5795669  34.5795669
##  [7]  33.2935756  30.9723202  29.7940604  28.1133768  26.1848746  24.1133768
## [13]  23.5080691  22.8655582  21.9008224  21.7206235  21.1848746  20.7206235
## [19]  20.0085539  19.6491257  19.1848746  18.7206235  18.3298093  17.1848746
## [25]  15.3278703  13.3650735  13.2563725  12.7206235  12.2563725  12.1505800
## [31]  11.3278703  11.3278703  10.2563725   9.6510648   9.3278703   8.9351170
## [37]   8.7930909   7.8636192   6.2573420   4.3278703   1.9351170   1.9351170
## [43]   0.3650735  -1.4576363  -1.8494200  -1.9209178  -1.9561820  -2.9933852
## [49]  -3.0648830  -3.6721297  -4.3489352  -4.5291341  -4.9933852  -5.0286493
## [55]  -5.1706755  -5.9933852  -7.8141559  -8.1001471  -8.7416885  -8.8141559
## [61]  -9.1706755  -9.3136711  -9.6006319  -9.9218873 -10.0639135 -10.1344418
## [67] -10.7073939 -11.3861384 -11.5291341 -12.0639135 -13.0639135 -13.3861384
## [73] -14.3861384 -15.8846842 -16.1001471 -16.3861384 -16.4214026 -16.7426580
## [79] -17.0629440 -17.0991776 -17.1716450 -17.4929004 -18.2069091 -19.3136711
## [85] -20.4566667 -21.2784069 -21.4929004 -22.1354113 -23.2069091 -24.1716450
## [91] -26.7416885 -26.9924157 -27.1001471 -29.0286493 -30.5643982 -32.4214026
## [97] -32.8856537 -33.5643982 -95.0639135

Dan untuk menjumlahkan error menggunakan fungsi sum

sum(Utils$error)
## [1] -1.355716e-11

dan untuk menunjuukan grafiknya digunakan visualisasi data sebagai berikut

Utils$error
##  [1]  13.3650735  33.2935756  22.8655582 -22.1354113  34.5795669   7.8636192
##  [7]  -5.9933852   4.3278703  40.8655582 -13.3861384 -17.1716450  -8.8141559
## [13]  12.1505800  18.3298093  37.5080691  -1.8494200 -21.4929004   1.9351170
## [19]  20.7206235  11.3278703  -2.9933852   6.2573420   0.3650735  23.5080691
## [25]  -9.3136711 -21.2784069   1.9351170  11.3278703  26.1848746   8.9351170
## [31] -16.4214026   8.7930909   9.6510648  -7.8141559  36.5795669  21.9008224
## [37]  -9.6006319 -32.4214026 -11.3861384  17.1848746 -29.0286493  -1.9209178
## [43]  20.0085539  21.7206235  58.0438180 -14.3861384  30.9723202 -26.7416885
## [49]   9.3278703  -3.6721297 -23.2069091  -1.4576363  83.7568572 -95.0639135
## [55]  29.7940604 -16.1001471  -5.0286493  -8.1001471  12.2563725  -3.0648830
## [61]  28.1133768  15.3278703 -27.1001471  -4.3489352 -12.0639135  -5.1706755
## [67] -15.8846842 -19.3136711 -17.4929004 -10.7073939  13.2563725  24.1133768
## [73]  19.6491257 -16.3861384 -10.0639135  -9.1706755 -32.8856537  -1.9561820
## [79] -17.0629440 -20.4566667 -16.7426580  -9.9218873  10.2563725  19.1848746
## [85]  12.7206235  -4.5291341 -24.1716450 -13.0639135  -8.7416885 -17.0991776
## [91] -10.1344418 -18.2069091  18.7206235 -33.5643982 -11.5291341  -4.9933852
## [97]  21.1848746 -30.5643982 -26.9924157
gf_point(year ~ error,data=Utils)

Grafik diatas menunjukkan hubungan data error setiap bulan,mengapa dalam bulan?, karena suhu rata-rata yang tercatat dalam datasets diatas diambil per bulan, seperti pepatah data is new oil, jadi data yang diolah yang penting saja

Sumber : https://dtkaplan.github.io/RforCalculus/fitting-functions-to-data.html#fitmodel