-
Notifications
You must be signed in to change notification settings - Fork 3
/
R_demo.r
145 lines (93 loc) · 3.66 KB
/
R_demo.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Databricks notebook source
# MAGIC %md
# MAGIC ### DEMO: Cluster + PreInstalled R Packages
# MAGIC
# MAGIC <!-- (init script: append `R_LIB_PATH_MOUNTED` with pre-installed packages to `.libPaths()` as `/root/.Rprofile`) -->
# MAGIC
# MAGIC <!--
# MAGIC Cluster: `mmt_14.3LTSML_cpu_(fasterlibloads_r)`
# MAGIC
# MAGIC Volumes init: `/Volumes/mmt_external/dais24/ext_vols/init_scripts/r_profile_init.sh`
# MAGIC -->
# COMMAND ----------
# DBTITLE 1,Check `.libPaths()`
.libPaths()
# COMMAND ----------
# MAGIC %md
# MAGIC ### Load up some libraries!
# COMMAND ----------
# DBTITLE 1,rcompanion
library(rcompanion)
# COMMAND ----------
# DBTITLE 1,compareLM: Compare fit statistics for linear models
rcompanion::compareLM
# COMMAND ----------
# MAGIC %md
# MAGIC ### Let's test it out
# COMMAND ----------
# DBTITLE 1,Load up dataset
BrendonSmall <- rcompanion::BrendonSmall
BrendonSmall
# COMMAND ----------
# DBTITLE 1,Define a few different linear models
BrendonSmall$Calories = as.numeric(BrendonSmall$Calories)
BrendonSmall$Calories2 = BrendonSmall$Calories * BrendonSmall$Calories
BrendonSmall$Calories3 = BrendonSmall$Calories * BrendonSmall$Calories * BrendonSmall$Calories
BrendonSmall$Calories4 = BrendonSmall$Calories * BrendonSmall$Calories * BrendonSmall$Calories * BrendonSmall$Calories
model.1 = lm(Sodium ~ Calories, data = BrendonSmall)
model.2 = lm(Sodium ~ Calories + Calories2, data = BrendonSmall)
model.3 = lm(Sodium ~ Calories + Calories2 + Calories3, data = BrendonSmall)
model.4 = lm(Sodium ~ Calories + Calories2 + Calories3 + Calories4,
data = BrendonSmall)
rcompanion::compareLM(model.1, model.2, model.3, model.4)
# COMMAND ----------
# DBTITLE 1,Run pairwiseModelAnova to assess model fit
rcompanion::pairwiseModelAnova(model.1, model.2, model.3, model.4)
# COMMAND ----------
# DBTITLE 1,Q: loaded package location?
system.file(package="rcompanion")
# COMMAND ----------
# MAGIC %md
# MAGIC ---
# COMMAND ----------
# DBTITLE 1,Default DBR R package path for `ggplot2`
system.file(package="ggplot2")
# COMMAND ----------
# DBTITLE 1,However specific packages require different version dependencies
system.file(package = "ggiraphExtra") ## requires ggplot2 version: 3.5.0
# COMMAND ----------
# DBTITLE 1,Load library with specific lib.loc = pre-installed lib-path
library("ggiraphExtra", lib.loc=.libPaths()[7])
# ggiraphExtra::ggPoints
# COMMAND ----------
# DBTITLE 1,Q: loaded ggplot2 package location?
system.file(package="ggplot2") ## loaded dependecies are found on pre-installed path
# COMMAND ----------
mtcars
# COMMAND ----------
# DBTITLE 1,Version specific library/package loads
library(ggplot2, lib.loc = .libPaths()[7]) # ggiraphExtra require version 3.5.0
library(ggiraphExtra, lib.loc = .libPaths()[7])
library(ggiraph, lib.loc = .libPaths()[7])
library(plyr)
ggPoints(aes(x=wt,y=mpg,color=am),data=mtcars,method="lm")
# COMMAND ----------
iris
# COMMAND ----------
ggRadar(data=iris,aes(color=Species))
# COMMAND ----------
# DBTITLE 1,If just using ggplot2 -- either default/pre-installed package will work...
ggplot(diamonds, aes(carat, price, colour = clarity, group = clarity)) + geom_point(alpha = 0.5) + stat_smooth()
# COMMAND ----------
diamonds
# COMMAND ----------
# DBTITLE 0,Q: loaded ggplot2 package location?
system.file(package="ggplot2")
# COMMAND ----------
# DBTITLE 1,packages installed
installed_packages <- installed.packages()
packINFO <- data.frame(Package = installed_packages[, "Package"],
Version = installed_packages[, "Version"],
loc = installed_packages[, "LibPath"])
knitr::kable(packINFO, format = "markdown")
# COMMAND ----------