Kurva dan model linier untuk cardata
library(mosaicCalc)
## Loading required package: mosaic
## 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
##
## 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
Car <- read.csv("https://www.mosaic-web.org/go/datasets/cardata.csv")
head(Car)
## mpg pounds horsepower cylinders tons constant
## 1 16.9 3967.60 155 8 2.0 1
## 2 15.5 3689.14 142 8 1.8 1
## 3 19.2 3280.55 125 8 1.6 1
## 4 18.5 3585.40 150 8 1.8 1
## 5 30.0 1961.05 68 4 1.0 1
## 6 27.5 2329.60 95 4 1.2 1
gf_point(mpg ~ pounds, data = Car) %>%
gf_labs(y = "konsumsi bahan bakar",
x = "pounds")
f <- fitModel(mpg ~ A * pounds + B, data = Car)
gf_point(mpg ~ pounds, data = Car) %>%
slice_plot(f(pounds) ~ pounds)
f2 <- fitModel(
mpg ~ A * pounds + B + C *sqrt(pounds),
data = Car)
gf_point(
mpg ~ pounds, data = Car) %>%
slice_plot(f2(pounds) ~ pounds)
Carr1 <- fitModel(
horsepower ~ A + B * mpg + C * pounds,
data = Car)
contour_plot(
Carr1(mpg=Mpg, pounds=Pounds) ~ Mpg + Pounds,
domain(Mpg = 2:8, Pounds = range(0, 60000)))
logCar2 <- fitModel(
horsepower ~ A + B * mpg + C * pounds + D * mpg * pounds,
data = Car %>% mutate(logPrice = log10(horsepower)))
contour_plot(
logCar2(mpg=mp, pounds=po) ~ mp + po,
domain(mp = range(0, 8),po = range(0, 60000)))
car3 <- fitModel(
horsepower ~ A + B * mpg + C * pounds + D * mpg * pounds +
E * mpg^2 + F * pounds^2 + G * mpg^2 * pounds +
H * mpg * pounds^2,
data = Car)
gf_point(pounds ~ mpg, data = Car, fill = NA) %>%
contour_plot(
car3(mpg=mpg, pounds=pounds) ~ mpg + pounds)