R Markdown

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

Including Plots

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.

library("readxl")
baca_xls = read_excel("housing_up.xls")
## New names:
## • `` -> `...1`
baca_xls
## # A tibble: 6 × 20
##   ...1  Income IncomeP…¹ Crime…² Aband…³ Incom…⁴ NoCen…⁵ Expos…⁶ AirCo…⁷ TwoBa…⁸
##   <chr>  <dbl>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1 1       3914         5    39.6    12.6     2.6    32.3     5.5    52.3    13.9
## 2 2      10817        15    32.4    10       3.3    34.7     5      55.4    16.9
## 3 3      21097        30    26.7     7.1     2.3    28.1     2.4    61.7    24.8
## 4 4      34548        50    23.9     4.1     2.1    21.4     2.1    69.8    39.6
## 5 5      51941        70    21.4     2.3     2.4    14.9     1.4    73.9    51.2
## 6 6      72079        90    19.9     1.2     2       9.6     1      76.7    73.2
## # … with 10 more variables: MotorVehicle <dbl>, TwoVehicles <dbl>,
## #   ClothesWasher <dbl>, ClothesDryer <dbl>, Dishwasher <dbl>, Telephone <dbl>,
## #   DoctorVisitsUnder7 <dbl>, DoctorVisits7To18 <dbl>,
## #   NoDoctorVisitUnder7 <dbl>, NoDoctorVisit7To18 <dbl>, and abbreviated
## #   variable names ¹​IncomePercentile, ²​CrimeProblem, ³​AbandonedBuildings,
## #   ⁴​IncompleteBathroom, ⁵​NoCentralHeat, ⁶​ExposedWires, ⁷​AirConditioning,
## #   ⁸​TwoBathrooms
library(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
gf_point(height ~ age, data=datasets::Loblolly)

plot(baca_xls$Income,baca_xls$IncomePercentile)

hist(baca_xls$Income)

library(mosaicCalc)
## 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
Cherry <- datasets::AirPassengers
AirPassengers
##      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 1949 112 118 132 129 121 135 148 148 136 119 104 118
## 1950 115 126 141 135 125 149 170 170 158 133 114 140
## 1951 145 150 178 163 172 178 199 199 184 162 146 166
## 1952 171 180 193 181 183 218 230 242 209 191 172 194
## 1953 196 196 236 235 229 243 264 272 237 211 180 201
## 1954 204 188 235 227 234 264 302 293 259 229 203 229
## 1955 242 233 267 269 270 315 364 347 312 274 237 278
## 1956 284 277 317 313 318 374 413 405 355 306 271 306
## 1957 315 301 356 348 355 422 465 467 404 347 305 336
## 1958 340 318 362 348 363 435 491 505 404 359 310 337
## 1959 360 342 406 396 420 472 548 559 463 407 362 405
## 1960 417 391 419 461 472 535 622 606 508 461 390 432
as.table.default(Cherry)
##   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T 
## 112 118 132 129 121 135 148 148 136 119 104 118 115 126 141 135 125 149 170 170 
##   U   V   W   X   Y   Z  A1  B1  C1  D1  E1  F1  G1  H1  I1  J1  K1  L1  M1  N1 
## 158 133 114 140 145 150 178 163 172 178 199 199 184 162 146 166 171 180 193 181 
##  O1  P1  Q1  R1  S1  T1  U1  V1  W1  X1  Y1  Z1  A2  B2  C2  D2  E2  F2  G2  H2 
## 183 218 230 242 209 191 172 194 196 196 236 235 229 243 264 272 237 211 180 201 
##  I2  J2  K2  L2  M2  N2  O2  P2  Q2  R2  S2  T2  U2  V2  W2  X2  Y2  Z2  A3  B3 
## 204 188 235 227 234 264 302 293 259 229 203 229 242 233 267 269 270 315 364 347 
##  C3  D3  E3  F3  G3  H3  I3  J3  K3  L3  M3  N3  O3  P3  Q3  R3  S3  T3  U3  V3 
## 312 274 237 278 284 277 317 313 318 374 413 405 355 306 271 306 315 301 356 348 
##  W3  X3  Y3  Z3  A4  B4  C4  D4  E4  F4  G4  H4  I4  J4  K4  L4  M4  N4  O4  P4 
## 355 422 465 467 404 347 305 336 340 318 362 348 363 435 491 505 404 359 310 337 
##  Q4  R4  S4  T4  U4  V4  W4  X4  Y4  Z4  A5  B5  C5  D5  E5  F5  G5  H5  I5  J5 
## 360 342 406 396 420 472 548 559 463 407 362 405 417 391 419 461 472 535 622 606 
##  K5  L5  M5  N5 
## 508 461 390 432
Cherry <- datasets::trees
gf_point(Volume ~ Girth, data = Cherry)

g1 = spliner(Volume ~ Girth, data = Cherry)
## Warning in regularize.values(x, y, ties, missing(ties)): collapsing to unique
## 'x' values
g2 = connector(Volume ~ Girth, data = Cherry)
## Warning in regularize.values(x, y, ties, missing(ties), na.rm = na.rm):
## collapsing to unique 'x' values
slice_plot(g1(x) ~ x, domain(x = 6:17)) %>%
  slice_plot(g2(x) ~ x, color ="red") %>%
  gf_point(Volume ~ Girth, data = Cherry) %>%
  gf_labs(x = "Girth (inches)")

library(mosaicCalc)
g3 <- smoother(Volume ~ Girth, data = Cherry, span=)
gf_point(Volume~Girth, data=Cherry) %>%
  slice_plot(g3(Girth) ~ Girth) %>%
  gf_labs(x = "Girth (inches)")

g4 <- smoother(Volume ~ Girth, data=Cherry, span=1.0)
gf_point(Volume~Girth, data = Cherry) %>%
  slice_plot(g4(Girth) ~ Girth) %>%
  gf_labs(x = "Girth (inches)", y = "Wood volume")

g5 <- smoother(Volume ~ Girth+Height, 
               data = Cherry, span = 1.0)
gf_point(Height ~ Girth, data = Cherry) %>%
  contour_plot(g5(Girth, Height) ~ Girth + Height) %>%
  gf_labs(x = "Girth (inches)", 
          y = "Height (ft)", 
          title = "Volume (ft^140)")

gf_point(height ~ age, data=datasets::Loblolly)

f1 <- spliner(height ~ age, data = datasets::Loblolly)
## Warning in regularize.values(x, y, ties, missing(ties)): collapsing to unique
## 'x' values
f1(age = 8)
## [1] 20.68193
f2 <- connector(height ~ age, data = datasets::Loblolly)
## Warning in regularize.values(x, y, ties, missing(ties), na.rm = na.rm):
## collapsing to unique 'x' values
f2(age = 8)
## [1] 20.54729