Error in eval(predvars, data, env) : object 's' not found


I am having issues with my mixed effects regression modeling code using nlme. I am using Rpy2 to implement R functions on jupyter python notebook as a means to have a seamless workflow. The code pasted below worked perfectly fine when I implement it on my jupyter notebook on my anaconda platform installed on my macbook but it doesnt work on my R Studi setup on jupyter notebook on my ubuntu setup.

The code is below:
for inx in range(len(varlist)):
** fmla_fixed = Formula(''+varlist[inx]+' ~ 1')**
** fmla_random = Formula('~ 1 | EQID')**
** env = fmla_fixed.environment**
** env2 = fmla_random.environment**
** env2['EQID'] = (data_df.rx(1))**
** env[varlist[inx]] = (data_df.rx(16+inx))**
** ck_eventres = (lme(fixed=fmla_fixed, data = (dat_df), random = fmla_random, na_action = na_exclude, method="ML", control=lmeControl(opt = "optim")))**

Varlist is a long list of variable names that looks like this:
['PGV (cm/s)' 'PGA (g)' 'T0.010s' 'T0.020s' 'T0.022s' 'T0.025s' 'T0.029s'
'T0.030s' 'T0.032s' 'T0.035s' 'T0.036s' 'T0.040s' 'T0.042s' 'T0.044s'
'T0.045s' 'T0.046s' 'T0.048s' 'T0.050s' 'T0.055s' 'T0.060s' 'T0.065s'
'T0.067s' 'T0.070s' 'T0.075s' 'T0.080s' 'T0.085s' 'T0.090s' 'T0.095s'
'T0.100s' 'T0.110s' 'T0.120s' 'T0.130s' 'T0.133s' 'T0.140s' 'T0.150s'
'T0.160s' 'T0.170s' 'T0.180s' 'T0.190s' 'T0.200s' 'T0.220s' 'T0.240s'
'T0.250s' 'T0.260s' 'T0.280s' 'T0.290s' 'T0.300s' 'T0.320s' 'T0.340s'
'T0.350s' 'T0.360s' 'T0.380s' 'T0.400s' 'T0.420s' 'T0.440s' 'T0.450s'
'T0.460s' 'T0.480s' 'T0.500s' 'T0.550s' 'T0.600s' 'T0.650s' 'T0.667s'
'T0.700s' 'T0.750s' 'T0.800s' 'T0.850s' 'T0.900s' 'T0.950s' 'T1.000s'
'T1.100s' 'T1.200s' 'T1.300s' 'T1.400s' 'T1.500s' 'T1.600s' 'T1.700s'
'T1.800s' 'T1.900s' 'T2.000s' 'T2.200s' 'T2.400s' 'T2.500s' 'T2.600s'
'T2.800s' 'T3.000s' 'T3.200s' 'T3.400s' 'T3.500s' 'T3.600s' 'T3.800s'
'T4.000s' 'T4.200s' 'T4.400s' 'T4.600s' 'T4.800s' 'T5.000s' 'T5.500s'
'T6.000s' 'T6.500s' 'T7.000s' 'T7.500s' 'T8.000s' 'T8.500s' 'T9.000s'
'T9.500s' 'T10.000s']

The bolded code is equivalent to this in native R coding:

models <- lapply(varlist, function(x) {
f <- as.formula(substitute(logResi ~ 1, list(logResi =
lme(fixed=f, data = data_df, random = ~ 1 | EQID, na.action=na.exclude,
method="ML", control=lmeControl(opt = "optim"))})

Below is the full error output:

RRuntimeError Traceback (most recent call last)

~/.local/lib/python3.8/site-packages/rpy2/robjects/ in call(self, *args, **kwargs)
195 v = kwargs.pop(k)
196 kwargs[r_k] = v
--> 197 return (super(SignatureTranslatedFunction, self)
198 .call(*args, **kwargs))

~/.local/lib/python3.8/site-packages/rpy2/robjects/ in call(self, *args, **kwargs)
123 else:
124 new_kwargs[k] = conversion.py2rpy(v)
--> 125 res = super(Function, self).call(*new_args, **new_kwargs)
126 res = conversion.rpy2py(res)
127 return res

~/.local/lib/python3.8/site-packages/rpy2/rinterface_lib/ in _(*args, **kwargs)
42 def _cdata_res_to_rinterface(function):
43 def _(*args, **kwargs):
---> 44 cdata = function(*args, **kwargs)
45 # TODO: test cdata is of the expected CType
46 return _cdata_to_rinterface(cdata)

~/.local/lib/python3.8/site-packages/rpy2/ in call(self, *args, **kwargs)
622 error_occured))
623 if error_occured[0]:
--> 624 raise embedded.RRuntimeError(_rinterface._geterrmessage())
625 return res

RRuntimeError: Error in eval(predvars, data, env) : object 's' not found

Please if someone can help me understand why i keep getting this error. I have checked the variable names for typos, case sensitivity, etc. but i keep getting the error.

Do i need to add a column of "1" and label that 's'? i dont think that makes sense but if anyone has any suggestions please share it with me.

Thanks in advance.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.