Nama : Muhammad Nur Ramadhan

NIM : 230605110077

KELAS : C KALKULUS

DOSEN PENGAMPU : Prof. Dr. SUHARTONO, M.Kom

LEMBAGA : UIN MAULANA MALIK IBRAHIM MALANG


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
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
##      (status 2 uses the sf package in place of rgdal)
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D
library(mosaic)
b <- df2matrix(bodyfat, data = Body_fat)
A <- df2matrix(1, wrist, thigh, forearm, data = Body_fat)
x <- qr.solve(A, b)
x
##             bodyfat
## 1       -40.4700038
## wrist     0.2533051
## thigh     0.8181824
## forearm   0.2232146
##             bodyfat
## 1       -40.4700038
## wrist     0.2533051
## thigh     0.8181824
## forearm   0.2232146
f <- makeFun(x)
f
## function (wrist, thigh, forearm) 
## -40.4700037897818 * 1 + 0.253305146981964 * wrist + 0.818182409571163 * 
##     thigh + 0.223214640718424 * forearm
## <environment: 0x000002ac8e566b18>
## function (wrist, thigh, forearm) 
## -40.4700037897818 * 1 + 0.253305146981963 * wrist + 0.818182409571164 * 
##     thigh + 0.223214640718424 * forearm
## <environment: 0x7fd1b932eef0>
var(b)
##          bodyfat
## bodyfat 70.03582
##          bodyfat
## bodyfat 70.03582
bhat <- A %*% x
var(bhat)
##          bodyfat
## bodyfat 22.16637
##          bodyfat
## bodyfat 22.16637
var(bhat) / var(b)
##           bodyfat
## bodyfat 0.3165004
##           bodyfat
## bodyfat 0.3165004
var(b - bhat) / var(b)
##           bodyfat
## bodyfat 0.6834996
##           bodyfat
## bodyfat 0.6834996