This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the plot.
BAB6 Fungsi fitting ke data
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 Anda duga, hubungan yang kuat antara keduanya.
Housing = read.csv("http://www.mosaic-web.org/go/datasets/Income-Housing.csv")
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)",
n = "Average outdoor temperature (F)")
Dengan data utilitas, input adalah suhu, suhu. Output yang akan
dimodelkan adalah ccf. Agar sesuai dengan fungsi model dengan data, Anda
menuliskan rumus dengan nama input, parameter, dan output yang sesuai di
tempat yang tepat:
f <- fitModel(ccf ~ A * temp + B, data = Utils)
Output dariadalah fungsi dari bentuk matematika bentuk yang sama seperti yang Anda tentukan dalam argumen pertama (di sini,) dengan nilai numerik spesifik yang diberikan pada parameter untuk membuat fungsi paling cocok dengan data. Bagaimana cara mengetahui kuantitas mana dalam bentuk matematika yang merupakan variabel dan mana yang merupakan parameter? Apa pun yang terkandung dalam data yang digunakan untuk pemasangan adalah variabel (di sini); hal-hal lain (di sini, dan) adalah parameter.
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)
Contoh ini hanya melibatkan satu variabel input. Sepanjang ilmu alam dan
sosial, teknik yang sangat penting dan banyak digunakan adalah
menggunakan banyak variabel dalam proyeksi. Sebagai ilustrasi, lihat
data harga mobil vario bekas.
Vario <- read.csv("http://www.mosaic-web.org/go/datasets/used-hondas.csv")
head(Vario)
## 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
mod2 <- makeFun(447.03 + 1.378*temp - 63.21*sqrt(temp) ~ temp)
gf_point(ccf ~ temp, data=Utils) %>% # the data
slice_plot(mod2(temp) ~ temp) %>%
gf_labs(x = "Temperature (F)",
y = "Natural gas used (ccf)")