©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
?
In [1]:
%%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’
In [2]:
%%r
install.packages("faraway")
library(faraway)
?ilogit
In [3]:
%%r
m <- glm(data=dead.beetles, cbind(died, tested-died) ~ Dose, family=binomial(link=logit))
In [4]:
%%r
x <- seq(1.6, 1.9, by=0.01)
y <- ilogit(coef(m)["(Intercept)"] + x * coef(m)["Dose"])
In [5]:
%%r
coef(m)["Dose"]
In [6]:
%%r
coef(m)["(Intercept)"]
In [7]:
%%sh
pwd
ls -lh
In [13]:
%%sh
mkdir -p imagesFromR
ls -lh
In [14]:
%%r
#with(dead.beetles, plot(Dose, died/tested))
png("imagesFromR/plot1.png")
plot(dead.beetles$Dose, dead.beetles$died/dead.beetles$tested)
dev.off()
In [16]:
%%sh
pwd
ls -lh imagesFromR
In [ ]: