©2018 Raazesh Sainudiin. Attribution 4.0 International (CC BY 4.0)
How to run R
commands in SageMath
glm
model on the beetles dataWhy SageMath for R
?
%%r
to denote that the Code
cell is of language R
¶%%r
install.packages("Flury")
library(Flury)
data(dead.beetles)
One often needs several additional packages to run certain desired R
commands. Let's get some such packages.
Note: Once a package is installed on a particular machine using install.packages("wantedpackage")
then you only need to load that library using library(wantedpackage)
when you are using the same machine.
In other words, you don't have to install packages that are already installed and thus can be automatically found by R
in the default location it will be installed at. In the case below, you can see where the package was installed from the following line:
Installing package into ‘/home/raazesh/R/x86_64-pc-linux-gnu-library/3.4’
%%r
install.packages("faraway")
library(faraway)
?ilogit
%%r
m <- glm(data=dead.beetles, cbind(died, tested-died) ~ Dose, family=binomial(link=logit))
%%r
x <- seq(1.6, 1.9, by=0.01)
y <- ilogit(coef(m)["(Intercept)"] + x * coef(m)["Dose"])
%%r
coef(m)["Dose"]
%%r
coef(m)["(Intercept)"]
%%sh
pwd
ls -lh
%%sh
mkdir -p imagesFromR
ls -lh
%%r
#with(dead.beetles, plot(Dose, died/tested))
png("imagesFromR/plot1.png")
plot(dead.beetles$Dose, dead.beetles$died/dead.beetles$tested)
dev.off()
%%sh
pwd
ls -lh imagesFromR