LoginSignup
2
1

More than 5 years have passed since last update.

R :: mcmc関数見つからない問題

Posted at

解決法

mle4のバージョンを1.0.0未満に落とす。

http://qiita.com/R_Linux/items/4c3ccdbe61c088fac008
ここから、直接リンクを指定。
https://cran.r-project.org/src/contrib/Archive/lme4/

> packageVersion("lme4")
[1] ‘1.1.12’
> remove.packages("lme4")
Removing package from ‘/usr/local/Cellar/r/3.1.3/R.framework/Versions/3.1/Resources/library’
(as ‘lib’ is unspecified)
> package_version("lme4")
 エラー:  無効なバージョンの指定 ‘lme4’ です 
 追加情報:  14 件の警告がありました (警告を見るには warnings() を使って下さい) 
> packageVersion("lme4")
 以下にエラー packageVersion("lme4") :  パッケージ ‘lme4’ が見付かりません 

>install.packages ("http://cran.r-project.org/src/contrib/Archive/lme4/lme4_0.999375-31.tar.gz", repos = NULL )

### http だよ! httpsだとエラー吐くよ!!

quit()

##一度再起動するよ!
> packageVersion("lme4")
[1] ‘0.999375.31’

## 動いた..... 長い。3時間かかった。

なぜ使えないの?

R初心者にはきっついエラーでした。。。。
やっぱ環境構築って最高にしんどいよね。

こちらのコードが動かなかった。

# lmer()関数を使ったマルチレベルモデルの推定
# パッケージ
library(lme4)
# 固定効果:傾き、ランダム効果:切片
lph.lme1 <- lmer(LPH~POPD+EMP3D+(1|AREA), data=lph)
summary(lph.lme1)
ranef(lph.lme1)
# random.effects(lph.lme1)
# 固定効果:切片、ランダム効果:傾き
lph.lme2 <- lmer(LPH~1+(0+POPD+EMP3D|AREA), data=lph)
summary(lph.lme2)
# random.effects(lph.lme2)
ranef(lph.lme2)
# mcmcsamp()関数を使ったマルチレベルモデルのベイズ推定
lph.mcmc1 <- mcmcsamp(lph.lme1, n=1000)
print(lph.mcmc1)
densityplot(lph.mcmc1)
#
lph.mcmc2 <- mcmcsamp(lph.lme2, n=1000)
print(lph.mcmc2)
densityplot(lph.mcmc2)

エラー: 関数 "mcmcsamp" を見つけることができませんでした

となった。

2014年以降のバージョン、はmcmcsamp実装されてないらしい。versions >=1.0.0

最新版は1.1.9。


なぜ使えないのか?

2016.07.16日確認時点でのmcmc該当コードコメント欄にて、

##' @name pvalues
##' @aliases mcmcsamp
##' @title Getting p-values for fitted models
##' 
##' @description One of the most frequently asked questions about \code{lme4}
##' is "how do I calculate p-values for estimated parameters?"
##' Previous versions of \code{lme4} provided the \code{mcmcsamp}
##' function, which efficiently generated a Markov chain Monte Carlo sample
##' from the posterior distribution of the parameters, assuming
##' flat (scaled likelihood) priors. Due to difficulty in
##' constructing a version of \code{mcmcsamp} that was reliable
##' even in cases where the estimated random effect variances were near
##' zero (e.g. \url{https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q4/003115.html}), \code{mcmcsamp} has been withdrawn (or more precisely,
##' not updated to work with \code{lme4} versions >=1.0.0).
##'
##' Many users, including users of the \code{aovlmer.fnc} function
##' from the \code{languageR} package which relies on \code{mcmcsamp},
##' will be deeply disappointed by this lacuna. Users who need p-values have
##' a variety of options:
##' \itemize{
##' \item likelihood ratio tests via \code{anova} (MC,+)
##' \item profile confidence intervals via \code{\link{profile.merMod}} and \code{\link{confint.merMod}} (CI,+)
##' \item parametric bootstrap confidence intervals and model comparisons via \code{\link{bootMer}} (or \code{PBmodcomp} in the \code{pbkrtest} package) (MC/CI,*,+)
##' \item for random effects, simulation tests via the \code{RLRsim} package (MC,*)
##' \item for fixed effects, F tests via Kenward-Roger approximation using \code{KRmodcomp} from the \code{pbkrtest} package (MC)
##' \item \code{car::Anova} and \code{lmerTest::anova} provide wrappers for \code{pbkrtest}. \code{lmerTest::anova} also provides t tests via the Satterthwaite approximation (P,*)
##' }
##' In the list above, the methods marked \code{MC} provide explicit model comparisons; \code{CI} denotes confidence intervals; and \code{P} denotes parameter-level or sequential tests of all effects in a model. The starred (*) suggestions provide finite-size corrections (important when the number of groups is <50); those marked (+) support GLMMs as well as LMMs.
##' 
##' When all else fails, don't forget to keep p-values in perspective: \url{http://www.phdcomics.com/comics/archive.php?comicid=905}
##' 

Previous versions of \code{lme4} provided the \code{mcmcsamp}
function, which efficiently generated a Markov chain Monte Carlo sample
from the posterior distribution of the parameters, assuming
flat (scaled likelihood) priors. Due to difficulty in
constructing a version of \code{mcmcsamp} that was reliable
even in cases where the estimated random effect variances were near
zero (e.g. \url{https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q4/003115.html}), \code{mcmcsamp} has been withdrawn (or more precisely,
not updated to work with \code{lme4} versions >=1.0.0).

(翻訳?)以前のlme4のバージョンで提供されていたmcmcsamp関数は、効率的にマルコフ連鎖モンテカルロサンプルをパラメータの事後分布、仮定フラット(スケーリングされた可能性)事前確率から生成していた。
ランダム効果の推定に分散が0に近い場合のコードの構造が難しいので1.0.0以降では更新しないとなっている。

私の翻訳がダメで、
あんまり使わなくなった(使えないと発覚した?)理由がぶっちゃけわからないので、
すみません、どなたかご教授いただけると幸いです。。。。。

統計への道は長い。

参照

すごく助かりました。


http://web.sfc.keio.ac.jp/~maunz/wiki/index.php?%A5%D9%A5%A4%A5%BA%C5%FD%B7%D7%B1%E9%BD%AC2014_6
http://qiita.com/R_Linux/items/4c3ccdbe61c088fac008
https://cran.r-project.org/src/contrib/Archive/lme4/
http://hosho.ees.hokudai.ac.jp/~kubo/ce/LmerMcmc.html

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1