library(mosaicCalc)
## Warning: package 'mosaicCalc' was built under R version 4.1.3
## Loading required package: mosaic
## Warning: package 'mosaic' was built under R version 4.1.3
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## 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
## Loading required package: mosaicCore
## Warning: package 'mosaicCore' was built under R version 4.1.3
##
## Attaching package: 'mosaicCore'
## The following objects are masked from 'package:dplyr':
##
## count, tally
##
## 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
gf_point(ccf ~ temp, data = Utils) %>%
gf_labs(y = "Natural gas usage (ccf/month)",
x = "Average outdoor temperature (F)")
library(mosaic)
f <- fitModel(ccf ~ A * temp + B, data = Utils)
gf_point(ccf ~ temp, data = Utils) %>%
slice_plot(f(temp) ~ temp)
f2 <- fitModel(
ccf ~ A * temp + B + C *sqrt(temp),
data = Utils)
gf_point(
ccf ~ temp, data = Utils) %>%
slice_plot(f2(temp) ~ temp)
Hondas <- read.csv("http://www.mosaic-web.org/go/datasets/used-hondas.csv")
head(Hondas)
## Price Year Mileage Location Color Age
## 1 20746 2006 18394 St.Paul Grey 1
## 2 19787 2007 8 St.Paul Black 0
## 3 17987 2005 39998 St.Paul Grey 2
## 4 17588 2004 35882 St.Paul Black 3
## 5 16987 2004 25306 St.Paul Grey 3
## 6 16987 2005 33399 St.Paul Black 2
carPrice1 <- fitModel(
Price ~ A + B * Age + C * Mileage, data = Hondas
)
contour_plot(
carPrice1(Age = age, Mileage = miles) ~ age + miles,
domain(age=2:8, miles=range(0, 60000)))
carPrice2 <- fitModel(
Price ~ A + B * Age + C * Mileage + D * Age * Mileage,
data = Hondas)
contour_plot(
carPrice2(Age=age, Mileage=miles) ~ age + miles,
domain(age = range(0, 8), miles = range(0, 60000)))