This is an example of using Python and R together within a Jupyter notebook. First, let's generate some data within python.
In [2]:
import numpy
%load_ext rpy2.ipython
x=numpy.random.randn(100)
beta=3
y=beta*x+numpy.random.randn(100)
Now, we pass those two variables into R and perform linear regression, and get back the result.
In [5]:
%%R -i x,y -o beta_est
result=lm(y~x)
beta_est=result$coefficients
summary(result)
Now let's look at the contents of the variable that we got back (which should contain the parameter estimates)
In [7]:
print(beta_est)
In [ ]: