slice_plot() could not find function error - r

I'm following the book "Computer-age Calculus with R" but cannot run the function slice_plot( which is the first one used for graphing functions). The library mosaic, mosaicCalc and mosaicModel are installed. I don't know what I'm missing.
this is the code with the libraries required by the book:
library(mosaic)
library(mosaicCalc)
library(mosaicModel)
library(akima)
drug_remaining <- function(dose, duration, time_constant){
dose * exp(-duration / time_constant)
}
slice_plot(
drug_remaining(dose = 100, time_constant = 4, duration = t) ~ t,
domain(t = 0:20))

I've found the function slice_plot() and countour_plot() are still in development in a beta version of the mosaicCalc package, to use them we need to install the beta version running this code:
remotes::install_github("ProjectMOSAIC/mosaicCalc", ref="beta")
https://github.com/ProjectMOSAIC/mosaicCalc/issues/4

Related

Error: No tidy method for objects of class dgCMatrix

I'm trying out a package regarding double machine learning (https://rdrr.io/github/yixinsun1216/crossfit/) and in trying to run the main function dml(), I get the following "Error: No tidy method for objects of class dgCMatrix" using example dataframe data. When looking through the documentation (https://rdrr.io/github/yixinsun1216/crossfit/src/R/dml.R), I can't find anything wrong with how tidy() is used. Does anyone have any idea what could be going wrong here?
R version 4.2.1
I have already tried installing broom.mixed, although broomextra doesn't seem to be available for my R version, and the same problem occurs. Code used below;
install.packages("remotes")
remotes::install_github("yixinsun1216/crossfit", force = TRUE)
library("remotes")
library("crossfit")
library("broom.mixed")
library("broom")
# Effect of temperature and precipitation on corn yield in the presence of
# time and locational effects
data(corn_yield)
library(magrittr)
dml_yield <- "logcornyield ~ lower + higher + prec_lo + prec_hi | year + fips" %>%
as.formula() %>%
dml(corn_yield, "linear", n = 5, ml = "lasso", poly_degree = 3, score = "finite")

Usage of tf.keras within R

I want to convert my articial neural network implementations to the new tensorflow 2 platform, where keras is an implicit part of (tf.keras). Are there any recommended sources that explain the implementation of ANNs using tensorflow 2/tf.keras within R?
Furthermore, why there is an extra keras package from F. Chollet available, when keras is as mentioned an implicit part of tensorflow now?
Sorry guys maybe for such basic questions, but my own searches were unfortunately not crowned with success.
From original tensorflow documentation I extract the following Python code:
input1 = keras.layers.Input(shape=(16,))
x1 = keras.layers.Dense(8, activation='relu')(input1)
input2 = keras.layers.Input(shape=(32,))
x2 = keras.layers.Dense(8, activation='relu')(input2)
added = keras.layers.add([x1, x2])
out = keras.layers.Dense(4)(added)
model = keras.models.Model(inputs=[input1, input2], outputs=out)
My own R conversions are
library(tensorflow)
k <- tf$keras
l <- k$layers
input1 <- k$layers$Input(shape = c(16,?))
x1 <- k$layers$Dense(units = 8, activation = "relu") (input1)
input2 <- k$layers$Input(shape = c(32,?))
x2 <- k$layers$Dense(units = 8, activation = "relu") (input2)
added <- k$layers$add(inputs = c(x1,x2))
My question hopefully seems not to be too stupid, but I've problems to implement a python tuple resp. scalar into its R equivalent. So my question: How must the shape argument in the input layers be converted into R?
I think the following page should provide the answer to your question: https://blogs.rstudio.com/ai/posts/2019-10-08-tf2-whatchanges/.
In essence, your code should stay the same if you are using Keras with a version 2.2.4.1 or above. For more details, refer to the linked site above.

R: Glmer Model Error

By run of follow code in R:
m3 <- glmer(accoccur ~ Time + Year + Month + holiday + HolidayNum + (1 + Time | DistfKaraj) , data = accident, family = "binomial" , nAGQ =1)
Run stooped with this error:
Error in intI(i, n = x#Dim[1], dn[[1]], give.dn = FALSE) :
"anyNA" is not a BUILTIN function
anyNA() is a function that was introduced in R 3.1.0 -- search http://cran.r-project.org/src/base/NEWS for the function name. My guess is that you have the development version of lme4 (hosted here), which makes use of anyNA() (based on the blame, it was added in November 2014), but doesn't define it for you.
You have a few options:
Upgrade to at least R 3.1.0 -- current is 3.2.0.
Define anyNA() yourself, with anyNA <- function(x) any(is.na(x))
I'd recommend at least upgrading your version of R, unless you rely on packages that are unavailable in future versions.

Effective dose (ED) in the drc package

I'm using the drc package in R, and after calculating the model I try to use the function ED to get the effective dose at several levels (IC50, IC75, IC90...), however from time to time I get the following error message and I don't seem to find any information on how to solve it.
Error in EDlist(parmChosen, respLev[j], reference = reference, type = type, :
could not find function "EDhelper"
The package is properly installed and loaded, and after checking the documentation it seems EDhelper is indeed no function but rather something else required by the function which R doesn't seem to find anymore.
Sorry for the trouble but any help would be very much appreaciated!
I am unsure what the issue is, because I can't see your data. It may be that EDhelper has been discontinued. I am also working with Dose-Response curves in DRC, the following works for me:
mod1 <- drm(ratio ~ dose, weights = total, data = data_source1, type ="binomial", fct=LL.2())
ED(mod1, c(10, 20, 50, 90, 99), interval = "delta", reference = "control")
or perhaps
ED(mod1,50,interval="fls")

R rms package error when using rcs()

Been looking into Harrell's rms package for R and I am getting an error whenever I try to use the spline function rcs() inside a formula. This happens with all datasets. Is there some R setting I am missing?
library(rms)
df = read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
m = lrm(admit~ rcs(gre), df)
Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc, fractied = fractied) :
unused argument (fractied = fractied)
What is "fractied"? I haven't been able to find a clear explanation.
I'm using Windows 7, R version 3.1.0, rms version 4.2.0

Resources