Reputation: 14689
I need to extract the results of an R lme model called in python using rpy2. Extracting the coefficients with rx2 as follows :
model = nlme.lme(fixed=fixed, data=dfr, random=random, method="REML")
print model.rx2("coefficients")
Yields all the coefficients as follows:
$fixed
(Intercept) log.var1
12.571692 -2.929928
$random
$random$item
(Intercept) log.var1
12545646546 -5.189606e-16 8.276929e-16
$random$category
(Intercept) log.var1
0001544848484/DLMX -3.1909917 2.3938670
I want to extract the coefficient for log.var1
in the fixed part of the model. I tried the following, but I got NULL
print model.rx2("coefficients$fixed[2]")
#gives NULL
How can I get the coefficient for log.var1 ?
Upvotes: 0
Views: 595
Reputation: 11545
The method rx2
corresponds to R's [[
, which I understand to be identical to $
.
With that in mind, you can access the item called "fixed" within "coefficients" the same way you are already accessing "coefficients":
# Python sequences are zero-based
model.rx2("coefficients").rx2("fixed")[1]
or
# R vectors are one-based (so 1+1=2)
model.rx2("coefficients").rx2("fixed").rx(2)
Upvotes: 2