Question: Problem 1: Emulation of R in Python Demonstrate Python analogues of the following R code blocks from the previous homework. Hints: The Python statsmodels module
Problem 1: Emulation of R in Python
Demonstrate Python analogues of the following R code blocks from the previous homework. Hints:
The Python statsmodels module includes the submodule datasets which simulates the corresponding R package.
The R pairs function can be simulated using the pandas function scatter_matrix.
The seaborn function FacetGrid allows you to set up a grid in which each entry corresponds to a particular value of a conditioning variable. Use this, and the matplotlib scatter plot functionality, to simulate the R function coplot.
The statsmodels module mosaicplot can simulate the R function mosaicplot.
1.
from statsmodels import datasets %load_ext rpy2.ipython
%%R pairs(mtcars)
translate in to python
2.
%%R require(stats); require(graphics) coplot(circumference ~ age | Tree, data = Orange, show.given = FALSE)
translate into python
3.
%%R x <- apply(HairEyeColor, c(1, 2), sum) x mosaicplot(x)
translate in to python
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
