ラベル Statistics の投稿を表示しています。 すべての投稿を表示
ラベル Statistics の投稿を表示しています。 すべての投稿を表示

2022年9月14日水曜日

Juliaで作って学ぶベイズ統計学のコードを実行してみました

Juliaで作って学ぶベイズ統計学のJulia コードを実行してみた結果を,GItHubで公開してみています.

  1.  Juliaの基礎
  2. 数値計算の基礎
  3. 確率計算の基礎
  4. 確率分布の基礎
  5. 統計モデリングと推論
  6. 勾配を利用した近似推論手法
  7. 発展的な統計モデル

Jupyter Notebookが完成し次第,随時アップロードしていく予定です.


2022年7月26日火曜日

ベータ分布

   Pythonによるベイズ統計学入門に掲載されているコードを実行してみた際のメモです.

ベータ分布を描画するPythonのコード.

# -*- coding: utf-8 -*-
#%% NumPyの読み込み
import numpy as np
# SciPyのstatsモジュールの読み込み
import scipy.stats as st
# MatplotlibのPyplotモジュールの読み込み
import matplotlib.pyplot as plt
#%% ベータ分布の確率密度関数
q = np.linspace(0, 1, 250)
value_a = np.array([0.5, 1.0, 2.0, 4.0])
value_b = np.array([0.5, 1.0, 2.0, 4.0])
rows = value_a.shape[0]
cols = value_b.shape[0]
fig, ax = plt.subplots(rows, cols, sharex='all', sharey='all',
num=1, facecolor='w')
ax[0, 0].set_xlim(0.0, 1.0)
ax[0, 0].set_ylim(0.0, 4.5)
for row_index in range(rows):
a = value_a[row_index]
ax[row_index, 0].set_ylabel('$\\alpha$ = {0:3.1f}'.format(a),
fontsize=12)
for column_index in range(cols):
b = value_b[column_index]
ax[row_index, column_index].plot(q, st.beta.pdf(q, a, b), 'k-')
if row_index == 0:
ax[0, column_index].set_title('$\\beta$ = {0:3.1f}'.format(b),
fontsize=12)
plt.tight_layout()
plt.savefig('pybayes_fig_beta_distribution.png', dpi=300)
plt.show()


このコードを実行すると,以下の図が描画されます.この図はα,βを変えた時のベータ分布の形状です.

2022年7月25日月曜日

ベルヌーイ分布の成功確率の事前分布(一様分布,ベルヌーイ分布)

  Pythonによるベイズ統計学入門に掲載されているコードを実行してみた際のメモです.

ベルヌーイ分布の成功確率の事前分布(一様分布とベルヌーイ分布)を描画するPythonのコード.

# -*- coding: utf-8 -*-
#%% NumPyの読み込み
import numpy as np
# SciPyのstatsモジュールの読み込み
import scipy.stats as st
# MatplotlibのPyplotモジュールの読み込み
import matplotlib.pyplot as plt

# 日本語フォントの設定
from matplotlib.font_manager import FontProperties
import sys
if sys.platform.startswith('win'):
FontPath = 'C:\\Windows\\Fonts\\meiryo.ttc'
elif sys.platform.startswith('darwin'):
FontPath = '/System/Library/Fonts/ヒラギノ角ゴシック W4.ttc'
elif sys.platform.startswith('linux'):
FontPath = '/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf'
else:
print('このPythonコードが対応していないOSを使用しています.')
sys.exit()
jpfont = FontProperties(fname=FontPath)

#%% ベルヌーイ分布の成功確率qの事前分布
fig1 = plt.figure(num=1, facecolor='w')
q = np.linspace(0, 1, 250)
plt.plot(q, st.uniform.pdf(q), 'k-')
plt.plot(q, st.beta.pdf(q, 4, 6), 'k--')
plt.xlim(0, 1)
plt.ylim(0, 2.8)
plt.legend(['(A) 一様分布 ($\\alpha$ = 1, $\\beta$ = 1)',
'(B) ベータ分布 ($\\alpha$ = 4, $\\beta$ = 6)'],
loc='best', frameon=False, prop=jpfont)
plt.xlabel('成功確率 q', fontproperties=jpfont)
plt.ylabel('確率密度', fontproperties=jpfont)
plt.savefig('pybayes_fig_beta_prior.png', dpi=300)
plt.show()

これを実行すると,以下の図が表示されます.

コードの簡単な解説は以下の通りです.

# -*- coding: utf-8 -*-
全角文字である日本語を使用する場合には,様々な文字コードがある(JIS,EUC-JP,Shift JISなど)ので,どの文字コードを使用して作成したコードなのかを明記しておきます.

import numpy as np
# SciPyのstatsモジュールの読み込み
import scipy.stats as st
# MatplotlibのPyplotモジュールの読み込み
import matplotlib.pyplot as pot
NumPy, SciPy, MatPlotLibを読み込んでいます.

# 日本語フォントの設定
from matplotlib.font_manager import FontProperties
import sys
if sys.platform.startswith('win'):
FontPath = 'C:\\Windows\\Fonts\\meiryo.ttc'
elif sys.platform.startswith('darwin'):
FontPath = '/System/Library/Fonts/ヒラギノ角ゴシック W4.ttc'
elif sys.platform.startswith('linux'):
FontPath = '/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf'
else:
print('このPythonコードが対応していないOSを使用しています.')
sys.exit()
jpfont = FontProperties(fname=FontPath)
表示する日本語フォントを選択するために,
import sys
でパッケージ sys を読み込んで,使用しているシステムのOSを判定するための関数
sys.platform.startswith()
を使えるようにしています.この関数は,システムのOSの名前がある文字列(e.g. Windowsならばwin)で始まっていれば真(True),そうでなければ偽(False)を返します.
これを利用して,システムのOSを判定して,OSに標準で付属する日本語フォントをpyplotの作図関数が認識できるようにする命令です.

#%% ベルヌーイ分布の成功確率qの事前分布
fig1 = plt.figure(num=1, facecolor='w')
作図を行うための空白のキャンパスを用意しています.
plt.figure(num=1, facecolor='w)
のnum=1は図の番号を1にするという意味です.特に指定しない場合はpyplot関数です.
plt.figure()
を呼び出すために自動的に通し番号が振られます.
次の facecolor = 'w' というオプションは白地(w: white)のグラフを作成するためのものです.

q = np.linspace(0, 1, 250)
一様分布とベータ分布のグラフを描くための成功確率 q の値を0から1まで等間隔に変化させたグリッドを生成し,それを1次元のNumPy配列qに格納しています.

plt.plot(q, st.uniform.pdf(q), 'k-')
plt.plot(q, st.beta.pdf(q, 4, 6), 'k--')
関数 plt.plot()は,いくつかの点を2次元座標上に打ち,各点を線で結んでグラフにします.なので,各点の横軸と縦軸の座標データとしてplt.plot()に与えなければなりません.これは1次元のNumPy配列の形でplt.plot()に渡されます.
上の行では,一様分布のグラフ(uniform)を作成しています.
先に読み込んでいる
import scipy.stats as at
には,一様分布の確率密度関数 st.uniform.pdf() が含まれているので,これを利用して一様分布の確率密度を計算します.描画の際には'k-'で黒の線を指定しています.
次の行では,ベータ分布の確率密度を計算するため stats 関数 st.beta.pdf() を使用しています.描画の際には'k--'で黒の波線を指定しています.

plt.xlim(0, 1)
plt.ylim(0, 2.8)
関数plt.xlim()は,横軸(x軸)の範囲を指定する関数で,最初の数値が下限,次の数値が上限です.横軸はベルヌーイ分布の成功確率qなので,0を下限,1を上限としています.
plt.ylim() は縦軸(y軸)の範囲を指定する関数で,最初の数値が下限,次の数値が上限です.

plt.legend(['(A) 一様分布 ($\\alpha$ = 1, $\\beta$ = 1)',
'(B) ベータ分布 ($\\alpha$ = 4, $\\beta$ = 6)'],
loc='best', frameon=False, prop=jpfont)
関数plt.legend()は与えられた文字列を要素とするPythonのリスト(これはNumPy配列ではありません)を使って凡例を作成する関数です.
凡例をキレイに表示するために,3つのオプションがあり,'best'は最も見やすい場所に判例を自動的に配置する指示です.明示的に配置する場所を決める際には,'upper left',upper right',lower left' などとlocオプションを変えることで変更可能です.
frameon=False は凡例を囲む枠を省くというオプションです.デフォルトでは,凡例を囲む枠が表示されるので,Falseとして枠をなくしています.
prop=jpfontは,日本語フォントを凡例の表示に使用するためのオプションです.

plt.xlabel('成功確率 q', fontproperties=jpfont)
plt.ylabel('確率密度', fontproperties=jpfont)
関数 plt.xlabel() は横軸のラベルを指定する関数で,関数 plt.ylabel()は縦軸のラベルを指定する関数です.
ここでも,ラベルに使われる日本語フォントとして fontproperties = jpfont というオプションで指定しています.

plt.savefig('pybayes_fig_beta_prior.png', dpi=300)
plt.show()
作成した図を画像ファイルに保存したい際には,plt.savefig()の 'pybayes.fig.beta_prior.png' は保存する図の名前,形式(.png)です.

2019年7月25日木曜日

[R] 正則化パラメータの選択

Lasso推定値は正則化パラメータλの値に依存するため,λの値が異なると当然Lasso推定値も異なってきます.
特に,Lasso推定値の違いは変数選択の結果の違いに直接影響してくるため,正則化パラメータの値の選択は重要です.

前回の投稿(アメリカの犯罪例にLassoを適用)ではアメリカの犯罪データにLassoを適用しました.
その続きとして,用意した正則化パラメータの値ごとに10分割交差検証法を用いて得られた結果を図示すると下図のようになります.
上図において,y軸は誤差2乗和(交差検証法の値)で,x軸は正則化パラメータの対数値になります.赤色の点から伸びている帯は,10分割交差検証法で計算された10個の検証誤差の標準誤差を表します.また,縦の破線は,選択された正則化パラメータの位置を表します.

CVの値が最小になる正則化パラメータの値(λ = 3)に対応するモデルを最適なモデルとして選択しています.

上図を表示するには,前回の投稿(こちら)に引き続いて以下のように入力します.

まずはCVを計算します.
> res.cv <- cv.glmnet(x=X, y=y)

続いて,CV値の推移をプロットします.
> plot(res.cv, xlab="Logarithmic value of regularization parameter", ylab="Regression coefficient")

CV値が最小となる正則化パラメータの値を出力します.
> res.cv$lambda.min
[1] 15.15854

1標準誤差ルールにより選択された正則化パラメータの値を出力します.

> res.cv$lambda.1se
[1] 155.1523


2019年7月24日水曜日

[R] アメリカの犯罪例に Lasso を適用

スパース推定法による統計モデリング (統計学One Point)の 1.3 にある例を実行してみた結果のメモです.

アメリカ合衆国の都市における犯罪データに関して Lasso を適用する.

まずは,Lassoの代表的なパッケージである glmnet を読み込みます.glmnet パッケージのインストール方法はこちら
> ### Lasso
> library(glmnet)
Loading required package: Matrix
Loading required package: foreach
Loaded glmnet 2.0-18

基となるアメリカ合衆国の都市における犯罪データ(crime.txt *)には,以下の6つの項目を50の都市から取得した結果が記載されています.なお,crime.txtはこちらからダウンロードできるデータです.

X1 = total overall reported crime rate per 1 million residents
         人口100万人あたりの犯罪率(目的変数 Y とする)
X2 = reported violent crime rate per 100,000 residents
         人口10万人当たりの暴力的な犯罪率 ← 今回の例では使用しない
X3 = annual police funding in $/resident
         警察の年間資金($ /住民)(説明変数 X1 とする)
X4 = % of people 25 years+ with 4 yrs. of high school
         25歳以上で,高校を卒業した人の割合(説明変数 X2 とする)
X5 = % of 16 to 19 year-olds not in highschool and not highschool graduates.
         16〜19歳のうち,高校に通っていない,もしくは卒業していない人の割合(説明変数 X3 とする)
X6 = % of 18 to 24 year-olds in college
         18〜24歳のうち,大学生の割合(説明変数 X4 とする)

X7 = % of people 25 years+ with at least 4 years of college
         25歳以上で、4年制大学を卒業した人の割合(説明変数 X5 とする)

このデータに対して,X1のデータを目的変数(Y)とし,X3 - X7の5つを説明変数(X1 - X5)として回帰分析を行います.

まずは,データ(crime.txt)を読み込みます.
> crime <- read.table("crime.txt")  # Load crime data

"as.matrix" を用いて行列に変換します.
> crime <- as.matrix(crime)

どのデータを使用するか,また,目的変数,説明変数の設定を行います.
> X <- crime[, 3:7]  # Explanatory variable
> y <- crime[, 1]    # Objective variable

説明変数の標準化,目的変数の中心化を行います.
> X <- scale(X)      # Standardize explanatory variables
> y <- y - mean(y)   # Centralize objective variables
ただし,glmnet パッケージでは,説明変数を標準化しなくても,初期設定で標準化され,係数の推定値は元の尺度に戻して出力されるとのことです.

Lasso推定を行います.
> # Lasso estimation
> res <- glmnet(x=X, y=y)

解パス図の描画を行います.
> # Drawing Solution path
> plot(res, xvar="lambda", label=TRUE, 
+      xlab="Logarithmic value of regularization parameter", 
+      ylab="Regression coefficient", col="black", lwd=2.5) 

正則化パラーメータの値を 20 に固定して,係数の推定値を求めます.
> # Fix value of regularization parameter to 20
> res1 <- glmnet(x=X, y=y, lambda=20)
> res1$beta  # Estimated value of coefficient
5 x 1 sparse Matrix of class "dgCMatrix"
          s0
V3 133.50551
V4 -25.22804
V5  19.45576
V6   .      
V7   .      

上記の例のJupyter Notebookファイルは,GitHubStatical Modeling via Sparse Estimation.ipynbの"Apply Lasso on crime data"で見ることができます.

..-. --- --- - -.--- - . * crime.txt の中身
478 184 40 74 11 31 20
494 213 32 72 11 43 18
643 347 57 70 18 16 16
341 565 31 71 11 25 19
773 327 67 72 9 29 24
603 260 25 68 8 32 15
484 325 34 68 12 24 14
546 102 33 62 13 28 11
424 38 36 69 7 25 12
548 226 31 66 9 58 15
506 137 35 60 13 21 9
819 369 30 81 4 77 36
541 109 44 66 9 37 12
491 809 32 67 11 37 16
514 29 30 65 12 35 11
371 245 16 64 10 42 14
457 118 29 64 12 21 10
437 148 36 62 7 81 27
570 387 30 59 15 31 16
432 98 23 56 15 50 15
619 608 33 46 22 24 8
357 218 35 54 14 27 13
623 254 38 54 20 22 11
547 697 44 45 26 18 8
792 827 28 57 12 23 11
799 693 35 57 9 60 18
439 448 31 61 19 14 12
867 942 39 52 17 31 10
912 1017 27 44 21 24 9
462 216 36 43 18 23 8
859 673 38 48 19 22 10
805 989 46 57 14 25 12
652 630 29 47 19 25 9
776 404 32 50 19 21 9
919 692 39 48 16 32 11
732 1517 44 49 13 31 14
657 879 33 72 13 13 22
1419 631 43 59 14 21 13
989 1375 22 49 9 46 13
821 1139 30 54 13 27 12
1740 3545 86 62 22 18 15
815 706 30 47 17 39 11
760 451 32 45 34 15 10
936 433 43 48 26 23 12
863 601 20 69 23 7 12
783 1024 55 42 23 23 11
715 457 44 49 18 30 12
1504 1441 37 57 15 35 13
1324 1022 82 72 22 15 16

940 1244 66 67 26 18 16

Crime data

Crime data for 50 U.S cities.
The data (X1, X2, X3, X4, X5, X6, X7) are for each city.
X1 = total overall reported crime rate per 1 million residents
X2 = reported violent crime rate per 100,000 residents
X3 = annual police funding in $/resident
X4 = % of people 25 years+ with 4 yrs. of high school
X5 = % of 16 to 19 year-olds not in highschool and not highschool graduates.
X6 = % of 18 to 24 year-olds in college

X7 = % of people 25 years+ with at least 4 years of college


2019年7月23日火曜日

[R] glmnetパッケージをインストール

ターミナルからRを立ち上げます.
$ r

R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.7.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

During startup - Warning messages:
1: Setting LC_COLLATE failed, using "C" 
2: Setting LC_TIME failed, using "C" 
3: Setting LC_MESSAGES failed, using "C" 
4: Setting LC_MONETARY failed, using "C" 

glmnetがインストールされてない状態でglmnetを読み込もうとしても,以下のようにそのようなパッケージが存在しないと返ってきます.
> library(glmnet)
Error in library(glmnet) : there is no package called ‘glmnet’

インストールは以下のようにして行います.
> install.packages("glmnet")

すると,以下のようにCRANミラーを選択するよう支持されます.
Installing package into ‘/usr/local/lib/R/3.6/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors 

 1: 0-Cloud [https]                   2: Algeria [https]                
 3: Australia (Canberra) [https]      4: Australia (Melbourne 1) [https]
 5: Australia (Melbourne 2) [https]   6: Australia (Perth) [https]      
 7: Austria [https]                   8: Belgium (Ghent) [https]        
 9: Brazil (PR) [https]              10: Brazil (RJ) [https]            
11: Brazil (SP 1) [https]            12: Brazil (SP 2) [https]          
13: Bulgaria [https]                 14: Chile [https]                  
15: China (Hong Kong) [https]        16: China (Guangzhou) [https]      
17: China (Lanzhou) [https]          18: China (Shanghai) [https]       
19: Colombia (Cali) [https]          20: Czech Republic [https]         
21: Denmark [https]                  22: Ecuador (Cuenca) [https]       
23: Ecuador (Quito) [https]          24: Estonia [https]                
25: France (Lyon 1) [https]          26: France (Lyon 2) [https]        
27: France (Marseille) [https]       28: France (Montpellier) [https]   
29: France (Paris 2) [https]         30: Germany (Erlangen) [https]     
31: Germany (Göttingen) [https]      32: Germany (Münster) [https]      
33: Germany (Regensburg) [https]     34: Greece [https]                 
35: Hungary [https]                  36: Iceland [https]                
37: Indonesia (Jakarta) [https]      38: Ireland [https]                
39: Italy (Padua) [https]            40: Japan (Tokyo) [https]          
41: Japan (Yonezawa) [https]         42: Korea (Busan) [https]          
43: Korea (Gyeongsan-si) [https]     44: Korea (Seoul 1) [https]        
45: Korea (Ulsan) [https]            46: Malaysia [https]               
47: Mexico (Mexico City) [https]     48: Norway [https]                 
49: Philippines [https]              50: Serbia [https]                 
51: Spain (A Coruña) [https]         52: Spain (Madrid) [https]         
53: Sweden [https]                   54: Switzerland [https]            
55: Turkey (Denizli) [https]         56: Turkey (Mersin) [https]        
57: UK (Bristol) [https]             58: UK (London 1) [https]          
59: USA (CA 1) [https]               60: USA (IA) [https]               
61: USA (KS) [https]                 62: USA (MI 1) [https]             
63: USA (MI 2) [https]               64: USA (OR) [https]               
65: USA (TN) [https]                 66: USA (TX 1) [https]             
67: Uruguay [https]                  68: (other mirrors)                

ここでは,40番のJapan(Tokyo)を選択します.
Selection: 40

するとインストール*が始まります.

・・-・ --- --- - -・ --- - ・
* インストール時には以下のように表示されます.
also installing the dependencies ‘iterators’, ‘foreach’

trying URL 'https://cran.ism.ac.jp/src/contrib/iterators_1.0.10.tar.gz'
Content type 'application/x-gzip' length 290575 bytes (283 KB)
==================================================
downloaded 283 KB

trying URL 'https://cran.ism.ac.jp/src/contrib/foreach_1.4.4.tar.gz'
Content type 'application/x-gzip' length 360705 bytes (352 KB)
==================================================
downloaded 352 KB

trying URL 'https://cran.ism.ac.jp/src/contrib/glmnet_2.0-18.tar.gz'
Content type 'application/x-gzip' length 3862714 bytes (3.7 MB)
==================================================
downloaded 3.7 MB

During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
* installing *source* package ‘iterators’ ...
** package ‘iterators’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** testing if installed package can be loaded from final location
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** testing if installed package keeps a record of temporary installation path
* DONE (iterators)
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
* installing *source* package ‘foreach’ ...
** package ‘foreach’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** testing if installed package can be loaded from final location
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** testing if installed package keeps a record of temporary installation path
* DONE (foreach)
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
* installing *source* package ‘glmnet’ ...
** package ‘glmnet’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gfortran  -fPIC  -g -O2  -c glmnet5dpclean.f -o glmnet5dpclean.o
clang -I"/usr/local/Cellar/r/3.6.0_3/lib/R/include" -DNDEBUG   -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include  -fPIC  -g -O2  -c glmnet_init.c -o glmnet_init.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/Cellar/r/3.6.0_3/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o glmnet.so glmnet5dpclean.o glmnet_init.o -L/usr/local/opt/gcc/lib/gcc/9/gcc/x86_64-apple-darwin17/9.1.0 -L/usr/local/opt/gcc/lib/gcc/9 -lgfortran -lquadmath -lm -L/usr/local/Cellar/r/3.6.0_3/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
installing to /usr/local/lib/R/3.6/site-library/00LOCK-glmnet/00new/glmnet/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
During startup - Warning messages:
1: Setting LC_TIME failed, using "C" 
2: Setting LC_MESSAGES failed, using "C" 
3: Setting LC_MONETARY failed, using "C" 
** testing if installed package keeps a record of temporary installation path
* DONE (glmnet)

The downloaded source packages are in
‘/private/var/folders/sd/hzc6sg0j5tj5p340n4h992_r0000gn/T/RtmphxoZOU/downloaded_packages’