"colab.fan/r"というURLに、R言語ランタイムが設定済みのGoogle Colaboratoryがある（GPU環境）：Rを定義したipynbファイルのアップロード不要

####次のURLにアクセスすると、R言語のランタイムが設定されているColaboratoryが開きます。

###__*https://colab.fan/r*__

- __「編集」 -> 「ノートブックの設定」を開くと、「ランタイムのタイプ」欄が「R」になっています。__
- __また、「ハードウェア アクセラレータ」欄で「GPU」を選択することができます。__

![スクリーンショット 2020-12-31 20.49.55.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/862466/a0745b46-ac0a-b106-bc65-c6982a59301b.png)



###（ 参考にしたwebページ ）

- [R: Google ColaboratoryでRを使う](http://www.mishou.be/2020/09/24/r-google-colaboratory%E3%81%A7r%E3%82%92%E4%BD%BF%E3%81%86/)

> たびたび、Google ColaboratoryでのPythonの使用法を紹介してきましたが、Rも使えるようになったようです。
>
>通常のGoogle ColaboratoryからはRを使えません、、、たぶん。
>
>正式な対応かどうか不明ですが、次のリンクを開くとRを実行できます。
>
>  https://colab.fan/r

#使ってみた。

__qiitaにcopy&pasteするにあたり、以下の手順を踏みました。__

```
1. ColaboratoryからGUI操作で、「ファイル」 -> 「.ipynbをダウンロード」を実行
2. ローカルPCのTerminalで、% jupyter notebookを実行して、Jupyter Notebookをブラウザで起動
3. ローカルのブラウザで開かれたJupyter Notebookで、「１」でダウンロードしたipynbファイルを選択して、開く
4. Jupyter Notebookで、「ファイル」 -> 「名前を付けてダウンロード」 -> 「Markdown(.md）」を選択して実行
5. ローカルPCに、zipファイルができる。（画像ファイルと、markdown書式のテキストファイルが格納されている）
6. Qiitaに、markdowsをcopy&pasteし、画像ファイルをアップロードする。
```

この記事で動かしたRのコードを、上記のGoogle Colaboratory上で実行してみました。

- [R言語のパイプ演算子（%>%）とmap関数とbroomパッケージの組合せ技で、3本の回帰分析式をDataFrame型に一括適用する](https://qiita.com/Afo_guard_enthusiast/items/c5ca43929f4ae2c1cb05)

> 安井 翔太（著）『効果検証入門』（技術評論社）を読んでいて、Rのパイプ関数（%>%）が使い勝手が良さそうだったので、写経して使ってみた。

__実行したコードは、安井 翔太（著）『効果検証入門』（技術評論社）に掲載されているものです。__


```R:Colaboratory(R)
library(tidyverse)
```


    ── [1mAttaching packages[22m ─────────────────────────────────────── tidyverse 1.3.0 ──
    
    [32m✔[39m [34mggplot2[39m 3.3.2     [32m✔[39m [34mpurrr  [39m 0.3.4
    [32m✔[39m [34mtibble [39m 3.0.4     [32m✔[39m [34mdplyr  [39m 1.0.2
    [32m✔[39m [34mtidyr  [39m 1.1.2     [32m✔[39m [34mstringr[39m 1.4.0
    [32m✔[39m [34mreadr  [39m 1.4.0     [32m✔[39m [34mforcats[39m 0.5.0
    
    ── [1mConflicts[22m ────────────────────────────────────────── tidyverse_conflicts() ──
    [31m✖[39m [34mdplyr[39m::[32mfilter()[39m masks [34mstats[39m::filter()
    [31m✖[39m [34mdplyr[39m::[32mlag()[39m    masks [34mstats[39m::lag()
    



```R:Colaboratory(R)
iris$Sepal.Length
```

```
<style>
.list-inline {list-style: none; margin:0; padding: 0}
.list-inline>li {display: inline-block}
.list-inline>li:not(:last-child)::after {content: "\00b7"; padding: 0 .5ex}
</style>
<ol class=list-inline><li>5.1</li><li>4.9</li><li>4.7</li><li>4.6</li><li>5</li><li>5.4</li><li>4.6</li><li>5</li><li>4.4</li><li>4.9</li><li>5.4</li><li>4.8</li><li>4.8</li><li>4.3</li><li>5.8</li><li>5.7</li><li>5.4</li><li>5.1</li><li>5.7</li><li>5.1</li><li>5.4</li><li>5.1</li><li>4.6</li><li>5.1</li><li>4.8</li><li>5</li><li>5</li><li>5.2</li><li>5.2</li><li>4.7</li><li>4.8</li><li>5.4</li><li>5.2</li><li>5.5</li><li>4.9</li><li>5</li><li>5.5</li><li>4.9</li><li>4.4</li><li>5.1</li><li>5</li><li>4.5</li><li>4.4</li><li>5</li><li>5.1</li><li>4.8</li><li>5.1</li><li>4.6</li><li>5.3</li><li>5</li><li>7</li><li>6.4</li><li>6.9</li><li>5.5</li><li>6.5</li><li>5.7</li><li>6.3</li><li>4.9</li><li>6.6</li><li>5.2</li><li>5</li><li>5.9</li><li>6</li><li>6.1</li><li>5.6</li><li>6.7</li><li>5.6</li><li>5.8</li><li>6.2</li><li>5.6</li><li>5.9</li><li>6.1</li><li>6.3</li><li>6.1</li><li>6.4</li><li>6.6</li><li>6.8</li><li>6.7</li><li>6</li><li>5.7</li><li>5.5</li><li>5.5</li><li>5.8</li><li>6</li><li>5.4</li><li>6</li><li>6.7</li><li>6.3</li><li>5.6</li><li>5.5</li><li>5.5</li><li>6.1</li><li>5.8</li><li>5</li><li>5.6</li><li>5.7</li><li>5.7</li><li>6.2</li><li>5.1</li><li>5.7</li><li>6.3</li><li>5.8</li><li>7.1</li><li>6.3</li><li>6.5</li><li>7.6</li><li>4.9</li><li>7.3</li><li>6.7</li><li>7.2</li><li>6.5</li><li>6.4</li><li>6.8</li><li>5.7</li><li>5.8</li><li>6.4</li><li>6.5</li><li>7.7</li><li>7.7</li><li>6</li><li>6.9</li><li>5.6</li><li>7.7</li><li>6.3</li><li>6.7</li><li>7.2</li><li>6.2</li><li>6.1</li><li>6.4</li><li>7.2</li><li>7.4</li><li>7.9</li><li>6.4</li><li>6.3</li><li>6.1</li><li>7.7</li><li>6.3</li><li>6.4</li><li>6</li><li>6.9</li><li>6.7</li><li>6.9</li><li>5.8</li><li>6.8</li><li>6.7</li><li>6.7</li><li>6.3</li><li>6.5</li><li>6.2</li><li>5.9</li></ol>
```



```R:Colaboratory(R)
head(diamonds)
```


<table>
<caption>A tibble: 6 × 10</caption>
<thead>
	<tr><th scope=col>carat</th><th scope=col>cut</th><th scope=col>color</th><th scope=col>clarity</th><th scope=col>depth</th><th scope=col>table</th><th scope=col>price</th><th scope=col>x</th><th scope=col>y</th><th scope=col>z</th></tr>
	<tr><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;ord&gt;</th><th scope=col>&lt;ord&gt;</th><th scope=col>&lt;ord&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th></tr>
</thead>
<tbody>
	<tr><td>0.23</td><td>Ideal    </td><td>E</td><td>SI2 </td><td>61.5</td><td>55</td><td>326</td><td>3.95</td><td>3.98</td><td>2.43</td></tr>
	<tr><td>0.21</td><td>Premium  </td><td>E</td><td>SI1 </td><td>59.8</td><td>61</td><td>326</td><td>3.89</td><td>3.84</td><td>2.31</td></tr>
	<tr><td>0.23</td><td>Good     </td><td>E</td><td>VS1 </td><td>56.9</td><td>65</td><td>327</td><td>4.05</td><td>4.07</td><td>2.31</td></tr>
	<tr><td>0.29</td><td>Premium  </td><td>I</td><td>VS2 </td><td>62.4</td><td>58</td><td>334</td><td>4.20</td><td>4.23</td><td>2.63</td></tr>
	<tr><td>0.31</td><td>Good     </td><td>J</td><td>SI2 </td><td>63.3</td><td>58</td><td>335</td><td>4.34</td><td>4.35</td><td>2.75</td></tr>
	<tr><td>0.24</td><td>Very Good</td><td>J</td><td>VVS2</td><td>62.8</td><td>57</td><td>336</td><td>3.94</td><td>3.96</td><td>2.48</td></tr>
</tbody>
</table>


```R:Colaboratory(R)
qplot(carat, price, data = diamonds, colour = clarity)
```

![out4_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/862466/99c1fb9d-002b-d337-d776-3ac9378dea3f.png)



```R:Colaboratory(R)
qplot(carat, data = diamonds, geom = "density", colour = cut)
```

![out5_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/862466/6ee36a01-34ff-a14c-907f-da50857d3b67.png)

    



```R:Colaboratory(R)
csv_url = "http://www.minethatdata.com/Kevin_Hillstrom_MineThatData_E-MailAnalytics_DataMiningChallenge_2008.03.20.csv"
```

```R:Colaboratory(R)
library("tidyverse")
```

    ── [1mAttaching packages[22m ─────────────────────────────────────── tidyverse 1.3.0 ──
    
    [32m✔[39m [34mggplot2[39m 3.3.2     [32m✔[39m [34mpurrr  [39m 0.3.4
    [32m✔[39m [34mtibble [39m 3.0.4     [32m✔[39m [34mdplyr  [39m 1.0.2
    [32m✔[39m [34mtidyr  [39m 1.1.2     [32m✔[39m [34mstringr[39m 1.4.0
    [32m✔[39m [34mreadr  [39m 1.4.0     [32m✔[39m [34mforcats[39m 0.5.0
    
    ── [1mConflicts[22m ────────────────────────────────────────── tidyverse_conflicts() ──
    [31m✖[39m [34mdplyr[39m::[32mfilter()[39m masks [34mstats[39m::filter()
    [31m✖[39m [34mdplyr[39m::[32mlag()[39m    masks [34mstats[39m::lag()
    


```R:Colaboratory(R)
email_data <- read_csv(csv_url)
```

    
    [36m──[39m [1m[1mColumn specification[1m[22m [36m────────────────────────────────────────────────────────[39m
    cols(
      recency = [32mcol_double()[39m,
      history_segment = [31mcol_character()[39m,
      history = [32mcol_double()[39m,
      mens = [32mcol_double()[39m,
      womens = [32mcol_double()[39m,
      zip_code = [31mcol_character()[39m,
      newbie = [32mcol_double()[39m,
      channel = [31mcol_character()[39m,
      segment = [31mcol_character()[39m,
      visit = [32mcol_double()[39m,
      conversion = [32mcol_double()[39m,
      spend = [32mcol_double()[39m
    )
    
    



```R:Colaboratory(R)
summary(email_data)
```


        recency       history_segment       history             mens      
     Min.   : 1.000   Length:64000       Min.   :  29.99   Min.   :0.000  
     1st Qu.: 2.000   Class :character   1st Qu.:  64.66   1st Qu.:0.000  
     Median : 6.000   Mode  :character   Median : 158.11   Median :1.000  
     Mean   : 5.764                      Mean   : 242.09   Mean   :0.551  
     3rd Qu.: 9.000                      3rd Qu.: 325.66   3rd Qu.:1.000  
     Max.   :12.000                      Max.   :3345.93   Max.   :1.000  
         womens         zip_code             newbie         channel         
     Min.   :0.0000   Length:64000       Min.   :0.0000   Length:64000      
     1st Qu.:0.0000   Class :character   1st Qu.:0.0000   Class :character  
     Median :1.0000   Mode  :character   Median :1.0000   Mode  :character  
     Mean   :0.5497                      Mean   :0.5022                     
     3rd Qu.:1.0000                      3rd Qu.:1.0000                     
     Max.   :1.0000                      Max.   :1.0000                     
       segment              visit          conversion           spend        
     Length:64000       Min.   :0.0000   Min.   :0.000000   Min.   :  0.000  
     Class :character   1st Qu.:0.0000   1st Qu.:0.000000   1st Qu.:  0.000  
     Mode  :character   Median :0.0000   Median :0.000000   Median :  0.000  
                        Mean   :0.1468   Mean   :0.009031   Mean   :  1.051  
                        3rd Qu.:0.0000   3rd Qu.:0.000000   3rd Qu.:  0.000  
                        Max.   :1.0000   Max.   :1.000000   Max.   :499.000  



```R:Colaboratory(R)
male_df <- email_data %>% filter(segment != "Womens E-Mail")
```


```R:Colaboratory(R)
male_df <- email_data %>% filter(segment != "Womens E-Mail") %>% mutate(treatment = if_else(segment == "Mens E-Mail", 1, 0))
```


```R:Colaboratory(R)
head(male_df)
```


<table>
<caption>A tibble: 6 × 13</caption>
<thead>
	<tr><th scope=col>recency</th><th scope=col>history_segment</th><th scope=col>history</th><th scope=col>mens</th><th scope=col>womens</th><th scope=col>zip_code</th><th scope=col>newbie</th><th scope=col>channel</th><th scope=col>segment</th><th scope=col>visit</th><th scope=col>conversion</th><th scope=col>spend</th><th scope=col>treatment</th></tr>
	<tr><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th></tr>
</thead>
<tbody>
	<tr><td>6</td><td>3) $200 - $350</td><td>329.08</td><td>1</td><td>1</td><td>Rural</td><td>1</td><td>Web         </td><td>No E-Mail  </td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
	<tr><td>9</td><td>5) $500 - $750</td><td>675.83</td><td>1</td><td>0</td><td>Rural</td><td>1</td><td>Web         </td><td>Mens E-Mail</td><td>0</td><td>0</td><td>0</td><td>1</td></tr>
	<tr><td>9</td><td>5) $500 - $750</td><td>675.07</td><td>1</td><td>1</td><td>Rural</td><td>1</td><td>Phone       </td><td>Mens E-Mail</td><td>0</td><td>0</td><td>0</td><td>1</td></tr>
	<tr><td>2</td><td>2) $100 - $200</td><td>101.64</td><td>0</td><td>1</td><td>Urban</td><td>0</td><td>Web         </td><td>Mens E-Mail</td><td>1</td><td>0</td><td>0</td><td>1</td></tr>
	<tr><td>4</td><td>3) $200 - $350</td><td>241.42</td><td>0</td><td>1</td><td>Rural</td><td>1</td><td>Multichannel</td><td>No E-Mail  </td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
	<tr><td>3</td><td>1) $0 - $100  </td><td> 58.13</td><td>1</td><td>0</td><td>Urban</td><td>1</td><td>Web         </td><td>No E-Mail  </td><td>1</td><td>0</td><td>0</td><td>0</td></tr>
</tbody>
</table>




```R:Colaboratory(R)
summary_by_segment <- male_df %>% group_by(treatment) %>% summarise(conversion_rate = mean(conversion), spend_mean = mean(spend), count = n())
```

    `summarise()` ungrouping output (override with `.groups` argument)
    



```R:Colaboratory(R)
summary_by_segment
```


<table>
<caption>A tibble: 2 × 4</caption>
<thead>
	<tr><th scope=col>treatment</th><th scope=col>conversion_rate</th><th scope=col>spend_mean</th><th scope=col>count</th></tr>
	<tr><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;int&gt;</th></tr>
</thead>
<tbody>
	<tr><td>0</td><td>0.005726087</td><td>0.6527894</td><td>21306</td></tr>
	<tr><td>1</td><td>0.012531093</td><td>1.4226165</td><td>21307</td></tr>
</tbody>
</table>




```R:Colaboratory(R)
library(broom)
```


```R:Colaboratory(R)
formulae_vec <- c(spend ~ treatment + recency + channel,
                   spend ~ treatment + recency + channel + history,
                   history ~ treatment + recency + channel)
```


```R:Colaboratory(R)
print(formulae_vec)
```

    [[1]]
    spend ~ treatment + recency + channel
    
    [[2]]
    spend ~ treatment + recency + channel + history
    
    [[3]]
    history ~ treatment + recency + channel
    



```R:Colaboratory(R)
names(formulae_vec) <- paste("reg", LETTERS[1:3], sep="_")
```


```R:Colaboratory(R)
print(formulae_vec)
```

    $reg_A
    spend ~ treatment + recency + channel
    
    $reg_B
    spend ~ treatment + recency + channel + history
    
    $reg_C
    history ~ treatment + recency + channel
    



```R:Colaboratory(R)
formulae_vec
```


    $reg_A
    spend ~ treatment + recency + channel
    
    $reg_B
    spend ~ treatment + recency + channel + history
    
    $reg_C
    history ~ treatment + recency + channel




```R:Colaboratory(R)
models <- formulae_vec %>% enframe(name = "model_index", value="formula")
```


```R:Colaboratory(R)
models
```


<table>
<caption>A tibble: 3 × 2</caption>
<thead>
	<tr><th scope=col>model_index</th><th scope=col>formula</th></tr>
	<tr><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;list&gt;</th></tr>
</thead>
<tbody>
	<tr><td>reg_A</td><td>spend ~ treatment + recency + channel</td></tr>
	<tr><td>reg_B</td><td>spend ~ treatment + recency + channel + history</td></tr>
	<tr><td>reg_C</td><td>history ~ treatment + recency + channel</td></tr>
</tbody>
</table>




```R:Colaboratory(R)
models$formula
```


    [[1]]
    spend ~ treatment + recency + channel
    
    [[2]]
    spend ~ treatment + recency + channel + history
    
    [[3]]
    history ~ treatment + recency + channel




```R:Colaboratory(R)
df_models <- models %>%
                          mutate(model = map(.x = formula, .f = lm, data = male_df)) %>%
                          mutate(lm_result = map(.x = model, .f = tidy))
```


```R:Colaboratory(R)
print(df_models)
```

    [90m# A tibble: 3 x 4[39m
      model_index formula   model  lm_result       
      [3m[90m<chr>[39m[23m       [3m[90m<list>[39m[23m    [3m[90m<list>[39m[23m [3m[90m<list>[39m[23m          
    [90m1[39m reg_A       [90m<formula>[39m [90m<lm>[39m   [90m<tibble [5 × 5]>[39m
    [90m2[39m reg_B       [90m<formula>[39m [90m<lm>[39m   [90m<tibble [6 × 5]>[39m
    [90m3[39m reg_C       [90m<formula>[39m [90m<lm>[39m   [90m<tibble [5 × 5]>[39m



```R:Colaboratory(R)
print(df_models$model)
```

    [[1]]
    
    Call:
    .f(formula = .x[[i]], data = ..1)
    
    Coefficients:
     (Intercept)     treatment       recency  channelPhone    channelWeb  
         1.16712       0.77085      -0.06975      -0.21560      -0.04294  
    
    
    [[2]]
    
    Call:
    .f(formula = .x[[i]], data = ..1)
    
    Coefficients:
     (Intercept)     treatment       recency  channelPhone    channelWeb  
        0.481547      0.767705     -0.052525      0.136065      0.306813  
         history  
        0.001157  
    
    
    [[3]]
    
    Call:
    .f(formula = .x[[i]], data = ..1)
    
    Coefficients:
     (Intercept)     treatment       recency  channelPhone    channelWeb  
         592.524         2.716       -14.889      -303.935      -302.285  
    
    



```R:Colaboratory(R)
print(df_models$lm_result)
```

    [[1]]
    [90m# A tibble: 5 x 5[39m
      term         estimate std.error statistic     p.value
      [3m[90m<chr>[39m[23m           [3m[90m<dbl>[39m[23m     [3m[90m<dbl>[39m[23m     [3m[90m<dbl>[39m[23m       [3m[90m<dbl>[39m[23m
    [90m1[39m (Intercept)    1.17      0.242      4.83  0.000[4m0[24m[4m0[24m[4m1[24m38 
    [90m2[39m treatment      0.771     0.145      5.31  0.000[4m0[24m[4m0[24m[4m0[24m112
    [90m3[39m recency       -[31m0[39m[31m.[39m[31m0[39m[31m69[4m8[24m[39m    0.020[4m8[24m    -[31m3[39m[31m.[39m[31m35[39m  0.000[4m8[24m[4m1[24m[4m2[24m   
    [90m4[39m channelPhone  -[31m0[39m[31m.[39m[31m216[39m     0.237     -[31m0[39m[31m.[39m[31m911[39m 0.362      
    [90m5[39m channelWeb    -[31m0[39m[31m.[39m[31m0[39m[31m42[4m9[24m[39m    0.236     -[31m0[39m[31m.[39m[31m182[39m 0.856      
    
    [[2]]
    [90m# A tibble: 6 x 5[39m
      term         estimate std.error statistic     p.value
      [3m[90m<chr>[39m[23m           [3m[90m<dbl>[39m[23m     [3m[90m<dbl>[39m[23m     [3m[90m<dbl>[39m[23m       [3m[90m<dbl>[39m[23m
    [90m1[39m (Intercept)   0.482    0.306        1.57  0.116      
    [90m2[39m treatment     0.768    0.145        5.29  0.000[4m0[24m[4m0[24m[4m0[24m125
    [90m3[39m recency      -[31m0[39m[31m.[39m[31m0[39m[31m52[4m5[24m[39m   0.021[4m4[24m      -[31m2[39m[31m.[39m[31m46[39m  0.013[4m9[24m     
    [90m4[39m channelPhone  0.136    0.256        0.533 0.594      
    [90m5[39m channelWeb    0.307    0.255        1.20  0.229      
    [90m6[39m history       0.001[4m1[24m[4m6[24m  0.000[4m3[24m[4m1[24m[4m8[24m     3.64  0.000[4m2[24m[4m7[24m[4m2[24m   
    
    [[3]]
    [90m# A tibble: 5 x 5[39m
      term         estimate std.error statistic p.value
      [3m[90m<chr>[39m[23m           [3m[90m<dbl>[39m[23m     [3m[90m<dbl>[39m[23m     [3m[90m<dbl>[39m[23m   [3m[90m<dbl>[39m[23m
    [90m1[39m (Intercept)    593.       3.69     161.     0    
    [90m2[39m treatment        2.72     2.21       1.23   0.220
    [90m3[39m recency        -[31m14[39m[31m.[39m[31m9[39m      0.318    -[31m46[39m[31m.[39m[31m9[39m    0    
    [90m4[39m channelPhone  -[31m304[39m[31m.[39m       3.61     -[31m84[39m[31m.[39m[31m3[39m    0    
    [90m5[39m channelWeb    -[31m302[39m[31m.[39m       3.60     -[31m83[39m[31m.[39m[31m9[39m    0    
    



```R:Colaboratory(R)
df_results <- df_models %>%
                              mutate(formula = as.character(formula)) %>%
                              select(formula, model_index, lm_result) %>%
                              unnest(cols = c(lm_result))
```


```R:Colaboratory(R)
df_results
```


<table>
<caption>A tibble: 16 × 7</caption>
<thead>
	<tr><th scope=col>formula</th><th scope=col>model_index</th><th scope=col>term</th><th scope=col>estimate</th><th scope=col>std.error</th><th scope=col>statistic</th><th scope=col>p.value</th></tr>
	<tr><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th></tr>
</thead>
<tbody>
	<tr><td>spend ~ treatment + recency + channel          </td><td>reg_A</td><td>(Intercept) </td><td> 1.167116e+00</td><td>0.2417364677</td><td>  4.8280525</td><td>1.383521e-06</td></tr>
	<tr><td>spend ~ treatment + recency + channel          </td><td>reg_A</td><td>treatment   </td><td> 7.708477e-01</td><td>0.1452333602</td><td>  5.3076491</td><td>1.116026e-07</td></tr>
	<tr><td>spend ~ treatment + recency + channel          </td><td>reg_A</td><td>recency     </td><td>-6.975255e-02</td><td>0.0208290189</td><td> -3.3488159</td><td>8.122801e-04</td></tr>
	<tr><td>spend ~ treatment + recency + channel          </td><td>reg_A</td><td>channelPhone</td><td>-2.155973e-01</td><td>0.2365937168</td><td> -0.9112556</td><td>3.621659e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel          </td><td>reg_A</td><td>channelWeb  </td><td>-4.294017e-02</td><td>0.2362749089</td><td> -0.1817382</td><td>8.557891e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>(Intercept) </td><td> 4.815474e-01</td><td>0.3063759245</td><td>  1.5717535</td><td>1.160152e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>treatment   </td><td> 7.677050e-01</td><td>0.1452150356</td><td>  5.2866768</td><td>1.251709e-07</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>recency     </td><td>-5.252544e-02</td><td>0.0213566166</td><td> -2.4594459</td><td>1.391911e-02</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>channelPhone</td><td> 1.360652e-01</td><td>0.2555133772</td><td>  0.5325171</td><td>5.943707e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>channelWeb  </td><td> 3.068129e-01</td><td>0.2550203247</td><td>  1.2030921</td><td>2.289474e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>history     </td><td> 1.157031e-03</td><td>0.0003177463</td><td>  3.6413672</td><td>2.715151e-04</td></tr>
	<tr><td>history ~ treatment + recency + channel        </td><td>reg_C</td><td>(Intercept) </td><td> 5.925244e+02</td><td>3.6851373464</td><td>160.7875918</td><td>0.000000e+00</td></tr>
	<tr><td>history ~ treatment + recency + channel        </td><td>reg_C</td><td>treatment   </td><td> 2.716224e+00</td><td>2.2140014062</td><td>  1.2268392</td><td>2.198898e-01</td></tr>
	<tr><td>history ~ treatment + recency + channel        </td><td>reg_C</td><td>recency     </td><td>-1.488907e+01</td><td>0.3175267515</td><td>-46.8907458</td><td>0.000000e+00</td></tr>
	<tr><td>history ~ treatment + recency + channel        </td><td>reg_C</td><td>channelPhone</td><td>-3.039354e+02</td><td>3.6067389830</td><td>-84.2687451</td><td>0.000000e+00</td></tr>
	<tr><td>history ~ treatment + recency + channel        </td><td>reg_C</td><td>channelWeb  </td><td>-3.022850e+02</td><td>3.6018789341</td><td>-83.9242660</td><td>0.000000e+00</td></tr>
</tbody>
</table>




```R:Colaboratory(R)
df_results %>% filter(model_index == "reg_A")
```


<table>
<caption>A tibble: 5 × 7</caption>
<thead>
	<tr><th scope=col>formula</th><th scope=col>model_index</th><th scope=col>term</th><th scope=col>estimate</th><th scope=col>std.error</th><th scope=col>statistic</th><th scope=col>p.value</th></tr>
	<tr><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th></tr>
</thead>
<tbody>
	<tr><td>spend ~ treatment + recency + channel</td><td>reg_A</td><td>(Intercept) </td><td> 1.16711637</td><td>0.24173647</td><td> 4.8280525</td><td>1.383521e-06</td></tr>
	<tr><td>spend ~ treatment + recency + channel</td><td>reg_A</td><td>treatment   </td><td> 0.77084771</td><td>0.14523336</td><td> 5.3076491</td><td>1.116026e-07</td></tr>
	<tr><td>spend ~ treatment + recency + channel</td><td>reg_A</td><td>recency     </td><td>-0.06975255</td><td>0.02082902</td><td>-3.3488159</td><td>8.122801e-04</td></tr>
	<tr><td>spend ~ treatment + recency + channel</td><td>reg_A</td><td>channelPhone</td><td>-0.21559735</td><td>0.23659372</td><td>-0.9112556</td><td>3.621659e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel</td><td>reg_A</td><td>channelWeb  </td><td>-0.04294017</td><td>0.23627491</td><td>-0.1817382</td><td>8.557891e-01</td></tr>
</tbody>
</table>




```R:Colaboratory(R)
df_results %>% filter(model_index == "reg_B")
```


<table>
<caption>A tibble: 6 × 7</caption>
<thead>
	<tr><th scope=col>formula</th><th scope=col>model_index</th><th scope=col>term</th><th scope=col>estimate</th><th scope=col>std.error</th><th scope=col>statistic</th><th scope=col>p.value</th></tr>
	<tr><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th></tr>
</thead>
<tbody>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>(Intercept) </td><td> 0.481547430</td><td>0.3063759245</td><td> 1.5717535</td><td>1.160152e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>treatment   </td><td> 0.767704959</td><td>0.1452150356</td><td> 5.2866768</td><td>1.251709e-07</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>recency     </td><td>-0.052525442</td><td>0.0213566166</td><td>-2.4594459</td><td>1.391911e-02</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>channelPhone</td><td> 0.136065239</td><td>0.2555133772</td><td> 0.5325171</td><td>5.943707e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>channelWeb  </td><td> 0.306812940</td><td>0.2550203247</td><td> 1.2030921</td><td>2.289474e-01</td></tr>
	<tr><td>spend ~ treatment + recency + channel + history</td><td>reg_B</td><td>history     </td><td> 0.001157031</td><td>0.0003177463</td><td> 3.6413672</td><td>2.715151e-04</td></tr>
</tbody>
</table>

___

#その他の方法

多少面倒ですが、以下の方法もあるようです。

- [2 Google ColaboratoryでR言語を使う](https://htsuda.net/stats/colab.html)

> Python を使う場合はこのまますぐにプログラムを書き始めることができるのですが、R を使うようにするにはちょっとした作業（ノートブックの書き換え）がまず必要です。
>
>画面左上のメニューの中から「ファイル」を選び、「.ipynbをダウンロード」を選びます。
（現在画面に表示中のノートブックのファイルが保存されます）
>
>ノートブックのファイルが保存されるので、これをメモ帳などのテキストエディタで開きます。
>
>そして、“kernelspec” にある name と display_name を以下のように書き換えます。
>
>```
>"kernelspec": {
>  "name": "ir",
>  "display_name": "R"
>}
>```
>
>書き換えができたら、このファイルをアップロードします。
>画面左上のメニューの中から「ファイル」を選び、「ノートブックをアップロード」を選びます。
>そして、書き換えを行ったノートブックファイルを選んでアップロードします。
>
>アップロードをすると、画面が更新されて、再び最初のノートブックの画面が表示されます。
>
>画面左上のメニューの中から「ランタイム」を選び、「ランタイムのタイプを変更」を選びます。
>これで R を使う準備ができました。