Entering edit mode
20 months ago
Mike
▴
10
Hi all, I hope this question belongs here since I'm analyzing biological data, if not I'll remove it.
I'm trying to convert a short R
data analysis script to python
and can't find the right modules/packages to do so.
This is the script in R
:
for(var in vars){
model<-lm(eval(parse(text=dep))~treatment,data = param)
org.lsm<-lsmeans(model,"treatment")
org.lsm <- confint(org.lsm, side = “=”, level = 0.95, type = "lsmean")
final = data.frame()
treatments = unique(param$treatment)
for (treat in treatments){
results<-list()
ind = paste0(treat)
results[[ind]]$A <- var
results[[ind]]$B <- param
results[[ind]]$C <- treat
results[[ind]]$N <- dim(param[param$treatment == treat,])[1]
results[[ind]]$LS <- org.lsm$lsmean[org.lsm$treatment==treat]
results[[ind]]$SE <- org.lsm$SE[org.lsm$Treatment==treat]
results[[ind]]$df <- org.lsm$df[org.lsm$Treatment==treat]
t=org.lsm$lsmean[org.lsm$treatment==treat]-0
t=t/org.lsm$SE[org.lsm$treatment==treat]
results[[ind]]$PVAL=round(2*pt(-abs(t),df=org.lsm$df[org.lsm$treatment==treat]),5)
if (is.na(results[[ind]]$PVAL)){stop("Message")}
results<-do.call("rbind.data.frame",results)
final <- rbind(final,results)
}
}
Basically I'm trying to understand just how to make the initial model in python
- not rewrite the whole script.
I found statsmodels
but can't seem to configure it so much as in the R
script. (the lsmeans
, confint
, SE
and more)
Any help with this will be highly appreciated!