bootstrap() function used in lmer object - r

I have a question pertaining to the R presentation by José A. Sánchez-Espigares and Jordi Ocaña entitled "An R implementation of bootstrap procedures for mixed models".
See: http://www.r-project.org/conferences/useR-2009/slides/SanchezEspigares+Ocana.pdf
On slide 22 on the examples they use the function bootstrap() (in the slide it is: sleep.boot=bootstrap(model,B=1000) ).
The only package they reference is lme4 but that package does not contain the bootstrap() function and I get:
Error: could not find function "bootstrap"
Does anybody know what package they are using here?

I am 99% sure that lme4 never had a bootstrap() function, and that it in fact came from code written by the presenters (I have looked for that code on-line before but have never found it). The built-in bootMer function tries to do most of what this presentation describes, but doesn't do everything (e.g. it doesn't include an implementation of a Wild bootstrap).
If you want to use bootMer without specifying a function FUN, you might take a look at confint(.,method="boot") ... it looks like the summary function that the authors used might have been something like
function(x) c(fixef(x),getME(x,"theta"),sigmaREML=sigma(x))

Related

unrecognized function Nn in R

I am learning R package SimInf to simulate data-driven stochastic epidemiological models. As I was reading the documentation I came across an unrecognized funcion Nn when defining a function for epicurves. Specifically, this line:
j <- sample(seq_len(Nn(model)), 1)
Values of model are integers. My guess is that Nn selects non-negative values, however my R does not recognize this function. From documentation it does not look like they pre-defined Nn either. Can someone please tell if they know what "Nn" is for? Thank you.
A way to go is always taking the package-name and triple-":" it, such that you can find nearly all functions inside the package. Maybe you are familiar with namespacing a function via packageName::functionFrompackageTocall. The packageName::: shows (nearly) all functions defined in this package. If you do this in R-Studio with SimInf:: and SimInf:::, you will see that the latter gives much more functions. But you can only find the functions SimInf:::Nd and SimInf:::Nc, not the Nn-function. Hence you will have to go to the github-sources of the package, in this case https://github.com/stewid/SimInf .Then search for Nn the whole repository. You will see that it seems like it is always an int, but this doesn't help you since you want to get ii as a function, not as a variable. Scrolling further down in the search-results, you will find the NEWS.md-file which mentions The 'Nn' function to determine the number of nodes in a model has been replaced with the S4 method 'n_nodes'. in the https://github.com/stewid/SimInf/blob/fd7eb4a29b82a4a97f64b528bb0e78e5474aa8a5/NEWS.md file under SimInf 8.0.0 (2020-09-13). Hence having a current version of SimInf installed, it shouldn't use the method Nn anymore. If you use it in your code, replace it by n_nodes. If you find it in current package code, you can email the package-maintainer that you found a bug in his code.
TLDR: Nn is an outdated version of n_nodes

Identifying required packages from code

I want to follow the tutorial found on this site, but despite being thorough in all other aspects, the author has not included information on what packages need to be used for the code to function.
As far as I understand one of them will be the PerformanceAnalytics package, yet my inexperienced eye is not sure about what else I will need to include.
The fapply function used in the code is one example that I cannot find.
fapply()
Error: could not find function "fapply"
library(sos)
findFn("fapply", sortby = "Function")
The findFN(...) function is great. It should open an internet browser window with the search results by itself at least it does for me.
The tutorial on Backtesting a Trading Strategy uses time series data as seen its part 1 and part 2. fapply is also used in part 2
As the data being collected and processed is time-series data, fapply() function belongs to far package which is used for Modelization for Functional AutoRegressive Processes.
I hope this helps.

I can't get fix() and names() to work (as intended in ISLR) on data set

I'm trying to work on data set Boston from MASS library following ISLR handbook. I am able to load MASS library with library() (I believe I can, because I ? Boston provides description of this data set), however I have problems with next steps.
ISLR is telling me to use
fix(Boston)
names(Boston)
First to learn more about data set, second to get names from it (I was able to perform both on previously used data set "Auto" few chapters before). However it doesn't work for me and when I run it:
fix(Boston) opens a Edit window containing only
function ()
{
}
names(Boston) returns simply NULL.
I read R documentation from stat.ethz.ch about both functions, but I don't know how to relate them to my problem. I wasn't able to use any Q&As I found on stack overflow about either function. From my understanding it seems like Boston isn't treated as data set or something like this, but I don't know where to go with this intuition either.
I'm using sixth printing of ISLR, related pages: 123-124.
If you do data("Boston") after loading the library, it fixes the problem.
The problem might be - R created an empty function Boston() because you might have run fix(Boston) before loading the required libraries.
So run
library(MASS)
library(ISLR)
data("Boston")
fix(Boston)
And everything works fine.

Code for summary-method in mirt package

I need to see the code for the summary function which is used in mirt package to see the factor loading matrix.
I have tried edit(summary) which in return giving me this
function (object, ...)
standardGeneric("summary")
which is not very helpful for me. How can I see the code for summary?
summary is a generic function. So you need to see the class-specific method for whatever type of object you're trying to summary-ize. E.g., see summary.lm (for lm objects). You don't specify the object class you're working with, so it's impossible to say what specific summary function you need to look at.
UPDATE: These are s4 generics, which is a bit more complicated than summary.lm, which is s3. Some quick googling reveals that you can see the relevant s4 methods on the package's Github page. The contents of summary will depend on what specific class you're looking at (and there appear to be four classes in the package):
Exploratory
Mixed
Confirmatory
MultipleGroup
This question and answer will also be helpful for addressing these kinds of questions in general in the future.

How to retrieve R function script from a specific package?

I realize there are generic functions like plot, predict for a list of packages. I am wondering how could I get the R script of these generic functions for a specific package, like the lme4::predict. I tried lme4::predict, but it comes with error:
> lme4::predict
Error: 'predict' is not an exported object from 'namespace:lme4'
Since you state that my suggestion above was helpful I will tell you my process. I used my own co-authored package called pacman. This package was developed because we had a hard time remembering all the obscurely named functions to get information on and work with add on packages.
I used this to figure out what you wanted:
library(pacman)
p_funs(lme4, all=TRUE)
I set all = TRUE as predict is a method for a specific class (like print, summary and plot). Generally, these methods are not exported so p_funs won't return them unless you set all = TRUE. Then I scrolled down to the p section and found only a single predict method: predict.merMod
Next I realized it wasn't exported so :: won't show me the stuff and extra colon power is needed, hence: lme4:::predict.merMod
As pointed out by David and rawr above, some functions can be suborn little snippets (methods etc.), thus methods and getAnywhere are helpful.
Here is an example of that:
library(tm)
dissimilarity #The good stuff is hid
methods(dissimilarity) #I want the good stuff
getAnywhere("dissimilarity.DocumentTermMatrix")
Small end note
And of course you don't need pacman to look at functions for packages, it's what I use and helpful but it just wraps base R things. Use THE SOURCE to figure out exactly what.

Resources