Skip to content

Commit bd8063e

Browse files
committed
Build vignettes for the pkgdown website and update README
1 parent 7c9d291 commit bd8063e

13 files changed

+83
-202
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
^docs$
1111
^pkgdown$
1212
^CRAN-SUBMISSION$
13+
^vignettes$

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Imports:
5050
Suggests:
5151
gganimate,
5252
gifski,
53-
gridExtra,
5453
knitr,
5554
plotly,
5655
png,

README.Rmd

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Here is a basic example on how to simulate a dataset with the adequate format, t
5050
```{r generate data Magma}
5151
library(MagmaClustR)
5252
## Simulate a dataset with 11 individuals, each observed at 10 input locations
53-
set.seed(28)
53+
set.seed(17)
5454
data_magma <- simu_db(M = 11, N = 10, common_input = FALSE)
5555
## Split individuals into training and prediction sets, and define test points
5656
magma_train <- data_magma %>% subset(ID %in% 1:10)
@@ -109,10 +109,9 @@ Here is a basic example on how to simulate a dataset with the adequate format, t
109109
### Data generation
110110

111111
```{r generate data MagmaClust}
112-
113112
## Simulate a dataset containing 3 clusters of 4 individuals, each observed at 10 input locations
114113
set.seed(4)
115-
data_magmaclust <- simu_db(M = 4, N = 10, K = 3)
114+
data_magmaclust <- simu_db(M = 4, N = 10, K = 3, common_input = FALSE)
116115
## Split individuals into training and prediction sets, and define test points
117116
list_ID = unique(data_magmaclust$ID)
118117
magmaclust_train <- data_magmaclust %>% subset(ID %in% list_ID[1:11])
@@ -149,7 +148,7 @@ plot_magmaclust(pred = pred_clust,
149148
data_train = data_train_with_clust,
150149
col_clust = TRUE,
151150
prior_mean = model_clust$hyperpost$mean,
152-
y_grid = seq(-15, 40, 0.5),
151+
y_grid = seq(10, 55, 0.5),
153152
heatmap = TRUE)
154153
```
155154

@@ -159,7 +158,6 @@ Although unidimensional-input problems are easier to visualise, both Magma and M
159158

160159
### Data generation
161160
```{r generate data 2-D}
162-
library(MagmaClustR)
163161
## Dataset with 11 individuals, 10 reference input locations and a covariate
164162
set.seed(5)
165163
data_dim2 <- simu_db(M = 11, N = 10, covariate = TRUE)
@@ -172,7 +170,7 @@ data_dim2
172170

173171
### Training and prediction with Magma
174172

175-
```{r train_and_predict_Magma_in_2-D, message=FALSE}
173+
```{r train_and_predict_Magma_in_2-D, message=FALSE, warning=FALSE}
176174
model_dim2 <- train_magma(data = dim2_train)
177175
178176
pred_dim2 <- pred_magma(data = dim2_pred,

README.md

Lines changed: 75 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ format, then train a Magma model and use it to perform predictions.
5858
``` r
5959
library(MagmaClustR)
6060
## Simulate a dataset with 11 individuals, each observed at 10 input locations
61-
set.seed(28)
61+
set.seed(17)
6262
data_magma <- simu_db(M = 11, N = 10, common_input = FALSE)
6363
## Split individuals into training and prediction sets, and define test points
6464
magma_train <- data_magma %>% subset(ID %in% 1:10)
@@ -67,20 +67,19 @@ magma_test <- data_magma %>% subset(ID == 11) %>% tail(3)
6767

6868
data_magma
6969
#> # A tibble: 110 x 3
70-
#> ID Output Input
71-
#> <chr> <dbl> <dbl>
72-
#> 1 1 -56.9 0
73-
#> 2 1 -57.4 0.7
74-
#> 3 1 -53.1 1
75-
#> 4 1 -62.8 1.5
76-
#> 5 1 -60.2 1.7
77-
#> 6 1 -81.4 5.2
78-
#> 7 1 -96.2 7
79-
#> 8 1 -102. 7.1
80-
#> 9 1 -96.4 8.05
81-
#> 10 1 -86.4 9.65
70+
#> ID Input Output
71+
#> <chr> <dbl> <dbl>
72+
#> 1 1 1.3 -20.7
73+
#> 2 1 2.65 -24.2
74+
#> 3 1 2.8 -24.4
75+
#> 4 1 3.3 -25.6
76+
#> 5 1 3.8 -23.9
77+
#> 6 1 5 -11.4
78+
#> 7 1 6.1 -4.97
79+
#> 8 1 6.35 -4.35
80+
#> 9 1 7.55 -6.63
81+
#> 10 1 9.8 -8.68
8282
#> # ... with 100 more rows
83-
#> # i Use `print(n = ...)` to see more rows
8483
```
8584

8685
As displayed above, any dataset processed in MagmaClustR should provide
@@ -97,21 +96,21 @@ model <- train_magma(data = magma_train, common_hp = F)
9796
#>
9897
#> The 'ini_hp_i' argument has not been specified. Random values of hyper-parameters for the individal processes are used as initialisation.
9998
#>
100-
#> EM algorithm, step 1: 8.23 seconds
99+
#> EM algorithm, step 1: 5.18 seconds
101100
#>
102-
#> Value of the likelihood: -434.32317 --- Convergence ratio = Inf
101+
#> Value of the likelihood: -313.47546 --- Convergence ratio = Inf
103102
#>
104-
#> EM algorithm, step 2: 4.91 seconds
103+
#> EM algorithm, step 2: 2.7 seconds
105104
#>
106-
#> Value of the likelihood: -401.89388 --- Convergence ratio = 0.08069
105+
#> Value of the likelihood: -303.47668 --- Convergence ratio = 0.03295
107106
#>
108-
#> EM algorithm, step 3: 4.18 seconds
107+
#> EM algorithm, step 3: 2.51 seconds
109108
#>
110-
#> Value of the likelihood: -400.50342 --- Convergence ratio = 0.00347
109+
#> Value of the likelihood: -302.84575 --- Convergence ratio = 0.00208
111110
#>
112-
#> EM algorithm, step 4: 3.53 seconds
111+
#> EM algorithm, step 4: 2.04 seconds
113112
#>
114-
#> Value of the likelihood: -400.21465 --- Convergence ratio = 0.00072
113+
#> Value of the likelihood: -302.56379 --- Convergence ratio = 0.00093
115114
#>
116115
#> The EM algorithm successfully converged, training is completed.
117116
#>
@@ -187,10 +186,9 @@ clustering and predictions.
187186
### Data generation
188187

189188
``` r
190-
191189
## Simulate a dataset containing 3 clusters of 4 individuals, each observed at 10 input locations
192-
set.seed(2)
193-
data_magmaclust <- simu_db(M = 4, N = 10, K = 3)
190+
set.seed(4)
191+
data_magmaclust <- simu_db(M = 4, N = 10, K = 3, common_input = FALSE)
194192
## Split individuals into training and prediction sets, and define test points
195193
list_ID = unique(data_magmaclust$ID)
196194
magmaclust_train <- data_magmaclust %>% subset(ID %in% list_ID[1:11])
@@ -199,20 +197,19 @@ magmaclust_test <- data_magmaclust %>% subset(ID == list_ID[12]) %>% tail(5)
199197

200198
data_magmaclust
201199
#> # A tibble: 120 x 3
202-
#> ID Output Input
203-
#> <chr> <dbl> <dbl>
204-
#> 1 ID1-Clust1 -47.0 0.25
205-
#> 2 ID1-Clust1 -39.5 0.8
206-
#> 3 ID1-Clust1 -29.7 2
207-
#> 4 ID1-Clust1 -38.7 4.2
208-
#> 5 ID1-Clust1 -43.4 4.6
209-
#> 6 ID1-Clust1 -53.6 6.2
210-
#> 7 ID1-Clust1 -57.5 6.75
211-
#> 8 ID1-Clust1 -64.9 7.95
212-
#> 9 ID1-Clust1 -53.3 8.85
213-
#> 10 ID1-Clust1 -42.7 9.85
200+
#> ID Input Output
201+
#> <chr> <dbl> <dbl>
202+
#> 1 ID1-Clust1 0.2 32.4
203+
#> 2 ID1-Clust1 0.7 28.8
204+
#> 3 ID1-Clust1 2.05 6.62
205+
#> 4 ID1-Clust1 2.1 5.46
206+
#> 5 ID1-Clust1 3.15 -5.44
207+
#> 6 ID1-Clust1 5.3 -16.5
208+
#> 7 ID1-Clust1 6.4 -24.7
209+
#> 8 ID1-Clust1 7.35 -31.4
210+
#> 9 ID1-Clust1 7.5 -32.4
211+
#> 10 ID1-Clust1 8.95 -42.7
214212
#> # ... with 110 more rows
215-
#> # i Use `print(n = ...)` to see more rows
216213
```
217214

218215
### Training and prediction with MagmaClust
@@ -227,21 +224,29 @@ model_clust <- train_magmaclust(data = magmaclust_train)
227224
#>
228225
#> The 'prior_mean' argument has not been specified. The hyper_prior mean function is thus set to be 0 everywhere.
229226
#>
230-
#> VEM algorithm, step 1: 44.73 seconds
227+
#> VEM algorithm, step 1: 20.02 seconds
228+
#>
229+
#> Value of the elbo: -712.16808 --- Convergence ratio = Inf
230+
#>
231+
#> VEM algorithm, step 2: 12.18 seconds
232+
#>
233+
#> Value of the elbo: -635.70636 --- Convergence ratio = 0.12028
234+
#>
235+
#> VEM algorithm, step 3: 14.54 seconds
231236
#>
232-
#> Value of the elbo: -454.05837 --- Convergence ratio = Inf
237+
#> Value of the elbo: -623.0371 --- Convergence ratio = 0.02033
233238
#>
234-
#> VEM algorithm, step 2: 14.69 seconds
239+
#> VEM algorithm, step 4: 10.76 seconds
235240
#>
236-
#> Value of the elbo: -409.05605 --- Convergence ratio = 0.11002
241+
#> Value of the elbo: -619.56266 --- Convergence ratio = 0.00561
237242
#>
238-
#> VEM algorithm, step 3: 14.16 seconds
243+
#> VEM algorithm, step 5: 8.23 seconds
239244
#>
240-
#> Value of the elbo: -408.61253 --- Convergence ratio = 0.00109
245+
#> Value of the elbo: -618.50147 --- Convergence ratio = 0.00172
241246
#>
242-
#> VEM algorithm, step 4: 14.46 seconds
247+
#> VEM algorithm, step 6: 10.46 seconds
243248
#>
244-
#> Value of the elbo: -408.20937 --- Convergence ratio = 0.00099
249+
#> Value of the elbo: -617.95297 --- Convergence ratio = 0.00089
245250
#>
246251
#> The EM algorithm successfully converged, training is completed.
247252
#>
@@ -275,9 +280,9 @@ plot_magmaclust(pred = pred_clust,
275280
data_train = data_train_with_clust,
276281
col_clust = TRUE,
277282
prior_mean = model_clust$hyperpost$mean,
278-
y_grid = seq(0, 60, 0.5),
283+
y_grid = seq(10, 55, 0.5),
279284
heatmap = TRUE)
280-
#> The mixture probability of the cluster K3 is 1. Therefore, the predictive distribution is Gaussian and the associated credible interval can be displayed.
285+
#> The mixture probability of the cluster K1 is 1. Therefore, the predictive distribution is Gaussian and the associated credible interval can be displayed.
281286
```
282287

283288
<img src="man/figures/README-display_MagmaClust-1.png" width="80%" style="display: block; margin: auto;" />
@@ -291,31 +296,28 @@ desired in the model.
291296
### Data generation
292297

293298
``` r
294-
library(MagmaClustR)
295299
## Dataset with 11 individuals, 10 reference input locations and a covariate
296-
set.seed(2)
300+
set.seed(5)
297301
data_dim2 <- simu_db(M = 11, N = 10, covariate = TRUE)
298302
## Split individuals into training and prediction sets, and define test points
299303
dim2_train <- data_dim2 %>% subset(ID %in% 1:10)
300-
dim2_pred <- data_dim2 %>% subset(ID == 11) %>% head(5)
301-
dim2_test <- data_dim2 %>% subset(ID == 11) %>% tail(5)
304+
dim2_pred <- data_dim2 %>% subset(ID == 11)
302305

303306
data_dim2
304307
#> # A tibble: 110 x 4
305-
#> ID Output Input Covariate
306-
#> <chr> <dbl> <dbl> <dbl>
307-
#> 1 1 -47.0 0.25 -2
308-
#> 2 1 -39.5 0.8 1.94
309-
#> 3 1 -29.7 2 4.64
310-
#> 4 1 -38.7 4.2 -3.7
311-
#> 5 1 -43.4 4.6 -4.24
312-
#> 6 1 -53.6 6.2 0.68
313-
#> 7 1 -57.5 6.75 0.55
314-
#> 8 1 -64.9 7.95 -4.38
315-
#> 9 1 -53.3 8.85 1.74
316-
#> 10 1 -42.7 9.85 4.14
308+
#> ID Input Covariate Output
309+
#> <chr> <dbl> <dbl> <dbl>
310+
#> 1 1 1.85 4.5 21.3
311+
#> 2 1 2.85 8.5 5.21
312+
#> 3 1 2 4 24.8
313+
#> 4 1 3.25 7 12.3
314+
#> 5 1 3.5 2.5 37.0
315+
#> 6 1 5.3 5.5 20.0
316+
#> 7 1 6.5 5 20.8
317+
#> 8 1 6 2 34.1
318+
#> 9 1 7.3 9.5 5.18
319+
#> 10 1 9.2 7.5 7.20
317320
#> # ... with 100 more rows
318-
#> # i Use `print(n = ...)` to see more rows
319321
```
320322

321323
### Training and prediction with Magma
@@ -328,89 +330,21 @@ model_dim2 <- train_magma(data = dim2_train)
328330
#>
329331
#> The 'ini_hp_i' argument has not been specified. Random values of hyper-parameters for the individal processes are used as initialisation.
330332
#>
331-
#> EM algorithm, step 1: 14.17 seconds
332-
#>
333-
#> Value of the likelihood: -547.76188 --- Convergence ratio = Inf
334-
#>
335-
#> EM algorithm, step 2: 9.5 seconds
336-
#>
337-
#> Value of the likelihood: -494.5156 --- Convergence ratio = 0.10767
338-
#>
339-
#> EM algorithm, step 3: 11.98 seconds
340-
#>
341-
#> Value of the likelihood: -466.4102 --- Convergence ratio = 0.06026
342-
#>
343-
#> EM algorithm, step 4: 9.24 seconds
344-
#>
345-
#> Value of the likelihood: -449.17074 --- Convergence ratio = 0.03838
346-
#>
347-
#> EM algorithm, step 5: 5 seconds
348-
#>
349-
#> Value of the likelihood: -435.574 --- Convergence ratio = 0.03122
350-
#>
351-
#> EM algorithm, step 6: 5.4 seconds
352-
#>
353-
#> Value of the likelihood: -426.56255 --- Convergence ratio = 0.02113
354-
#>
355-
#> EM algorithm, step 7: 5.17 seconds
356-
#>
357-
#> Value of the likelihood: -421.25636 --- Convergence ratio = 0.0126
358-
#>
359-
#> EM algorithm, step 8: 5.15 seconds
360-
#>
361-
#> Value of the likelihood: -417.61643 --- Convergence ratio = 0.00872
362-
#>
363-
#> EM algorithm, step 9: 5.11 seconds
364-
#>
365-
#> Value of the likelihood: -415.16894 --- Convergence ratio = 0.0059
366-
#>
367-
#> EM algorithm, step 10: 4.99 seconds
368-
#>
369-
#> Value of the likelihood: -413.38881 --- Convergence ratio = 0.00431
370-
#>
371-
#> EM algorithm, step 11: 4.8 seconds
372-
#>
373-
#> Value of the likelihood: -411.98102 --- Convergence ratio = 0.00342
374-
#>
375-
#> EM algorithm, step 12: 4.25 seconds
376-
#>
377-
#> Value of the likelihood: -410.94035 --- Convergence ratio = 0.00253
378-
#>
379-
#> EM algorithm, step 13: 4.25 seconds
380-
#>
381-
#> Value of the likelihood: -409.99426 --- Convergence ratio = 0.00231
382-
#>
383-
#> EM algorithm, step 14: 4.25 seconds
384-
#>
385-
#> Value of the likelihood: -409.21728 --- Convergence ratio = 0.0019
386-
#>
387-
#> EM algorithm, step 15: 4.35 seconds
388-
#>
389-
#> Value of the likelihood: -408.47281 --- Convergence ratio = 0.00182
390-
#>
391-
#> EM algorithm, step 16: 4.33 seconds
392-
#>
393-
#> Value of the likelihood: -407.67549 --- Convergence ratio = 0.00196
394-
#>
395-
#> EM algorithm, step 17: 4.42 seconds
396-
#>
397-
#> Value of the likelihood: -406.49068 --- Convergence ratio = 0.00291
398-
#>
399-
#> EM algorithm, step 18: 4.67 seconds
333+
#> EM algorithm, step 1: 5.42 seconds
400334
#>
401-
#> Value of the likelihood: -405.14487 --- Convergence ratio = 0.00332
335+
#> Value of the likelihood: -247.66608 --- Convergence ratio = Inf
402336
#>
403-
#> EM algorithm, step 19: 4.22 seconds
337+
#> EM algorithm, step 2: 5.39 seconds
404338
#>
405-
#> Value of the likelihood: -404.58873 --- Convergence ratio = 0.00137
339+
#> Value of the likelihood: -217.29028 --- Convergence ratio = 0.13979
406340
#>
407-
#> EM algorithm, step 20: 4.31 seconds
341+
#> EM algorithm, step 3: 3.04 seconds
408342
#>
409-
#> Value of the likelihood: -403.83303 --- Convergence ratio = 0.00187
343+
#> Value of the likelihood: -216.11346 --- Convergence ratio = 0.00545
410344
#>
411-
#> EM algorithm, step 21: 4.51 seconds
345+
#> EM algorithm, step 4: 3.04 seconds
412346
#>
413-
#> Value of the likelihood: -403.49586 --- Convergence ratio = 0.00084
347+
#> Value of the likelihood: -216.02699 --- Convergence ratio = 4e-04
414348
#>
415349
#> The EM algorithm successfully converged, training is completed.
416350
#>
@@ -425,10 +359,6 @@ pred_dim2 <- pred_magma(data = dim2_pred,
425359
#>
426360
#> Done!
427361
#>
428-
#> Warning: Raster pixels are placed at uneven horizontal intervals and will be
429-
#> shifted. Consider using geom_tile() instead.
430-
#> Warning: Raster pixels are placed at uneven vertical intervals and will be
431-
#> shifted. Consider using geom_tile() instead.
432362
```
433363

434364
<img src="man/figures/README-train_and_predict_Magma_in_2-D-1.png" width="80%" style="display: block; margin: auto;" />
-579 KB
Loading
-730 KB
Loading

man/figures/README-gif_Magma-1.gif

-1.22 MB
Loading
-46.6 KB
Loading
-116 KB
Loading

0 commit comments

Comments
 (0)