NAMA MAHASISWA : MUHAMMAD FAQIH
NIM : 220605110069
MATA KULIAH : KALKULUS
DOSEN PENGAMPU : Prof. Dr. Suhartono, M.Kom
JURUSAN : TEKNIK INFORMATIKA
UNIVERSITAS : UIN MAULANA MALIK IBRAHIM MALANG
BAB 6 : MENYESUAIKAN FUNGSI KE DATA
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
Utils <- read.csv("http://www.mosaic-web.org/go/datasets/utilities.csv")
gf_point(ccf ~ temp, data = Utils) %>%
gf_labs(y = "Natural gas usage (ccf/month)",
x = "Average outdoor temperature (F)")
Salah satu cara untuk merepresentasikan sebuah data yang sangat simple
yaitu Fungsi Garis lurus
f(x) = ax + b
Didalam fungsi f(x), variabel x digunakan untuk input, a dan b adalah parameter.
f <- fitModel(ccf ~ A * temp + B, data = Utils)
Output dari fitmodel () adalah fungsi dengan bentuk matematika
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
)
Kita bisa memplot fungsi yang sudah disesuaikan seperti dibawah ini.
library(mosaicCalc)
contour_plot(
carPrice1(Age = age, Mileage = miles) ~ age + miles,
domain(age=2:8, miles=range(0, 60000)))
carPrice3 <- fitModel(
Price ~ A + B * Age + C * Mileage + D * Age * Mileage +
E * Age^2 + F * Mileage^2 + G * Age^2 * Mileage +
H * Age * Mileage^2,
data = Hondas)
gf_point(Mileage ~ Age, data = Hondas, fill = NA) %>%
contour_plot(
carPrice3(Age=Age, Mileage=Mileage) ~ Age + Mileage)
library(mosaicCalc)
car_price2 <- makeFun(22137 - 7.495e2*age - 9.414e-2*miles +
3.450e-3*age*miles ~ age & miles)
contour_plot(
car_price2(Kualitas, Kuantitas ) ~ Kualitas + Kuantitas,
domain(Kualitas = range(0, 10), Kuantitas = range(0, 100000))) %>%
gf_labs(title = "Harga barang (IDR)")
Pemasangan Polinomial
polinomial sangat sering digunakan dalam pemodelan.
Utilities = read.csv("http://www.mosaic-web.org/go/datasets/utilities.csv")
project(ccf ~ 1 + temp + I(temp^2), data = Utilities)
## (Intercept) temp I(temp^2)
## 317.58743630 -6.85301947 0.03609138
I( ) digunakan untuk memberi tahu perangkat lunak untuk mengambil eksponen dalam matematika.
Koefisien memberi tahu kita bahwa model kuadrat ccf versus temp yang paling pas adalah:
ccfQuad <- makeFun(317.587 - 6.853*T + 0.0361*T^2 ~ T)
gf_point(ccf ~ temp, data = Utilities) %>%
slice_plot(ccfQuad(temp) ~ temp)
REFERENCES https://dtkaplan.github.io/RforCalculus/fitting-functions-to-data.html#curves-and-linear-models