I am using R 3.3.1 and Python 2.7 and rpy2 with R module RSGHB.

I make this code in R and I don't know how to translate it with rpy2.

I used import rpy2.robjects as ro & ro.r('''all code''')
but it didn't work.(Like
https://sites.google.com/site/aslugsguidetopython/data-analysis/pandas/calling-r-from-python
method1)
(return Null)
Can you help me to get a code?

Code is below.

data name is adobe1 and module name is RSGHB

day2 = (adobe1$day2)
hour1 = (adobe1$hour1)
company_size = (adobe1$company_size)
retailer_type = (adobe1$retailer_type)
mobiledevicetype = (adobe1$mobiledevicetype)
lasttouchchannel_3 = (adobe1$lasttouchchannel_3)
visits = (adobe1$visits)
pageview = (adobe1$pageview)
orders = (adobe1$orders)
units = (adobe1$units)
revenue = (adobe1$revenue)
order_yn = (adobe1$order_yn)
orderration = (adobe1$orderration)
average_vvp = (adobe1$average_vvp)
day2_Specialday = (adobe1$Specialday)
day2_Weekdays = (adobe1$Weekdays)
day2_Weeken = (adobe1$Weeken)
hour1_A = (adobe1$A)
hour1_B = (adobe1$B)
hour1_C = (adobe1$C)
company_size_big = (adobe1$big)
company_size_middle = (adobe1$middle)
company_size_small = (adobe1$small)
retailer_type_Apparel = (adobe1$Apparel)
retailer_type_Electronics = (adobe1$Electronics)
retailer_type_General_Merchandise = (adobe1$General_Merchandise)
retailer_type_Groceries = (adobe1$Groceries)
retailer_type_Home_Garden = (adobe1$Home_Garden)
retailer_type_Luxury = (adobe1$Luxury)
retailer_type_Sports_Outdoor = (adobe1$Sports_Outdoor)
retailer_type_Toys = (adobe1$Toys)
mobiledevicetype_EReader = (adobe1$EReader)
mobiledevicetype_Gaming_Console = (adobe1$Gaming_Console)
mobiledevicetype_Media_Player = (adobe1$Media_Player)
mobiledevicetype_Mobile_Phone = (adobe1$Mobile_Phone)
mobiledevicetype_PC = (adobe1$PC)
mobiledevicetype_Set_top_Box = (adobe1$Set_top_Box)
mobiledevicetype_Tablet = (adobe1$Tablet)
lasttouchchannel_3_Advertisement = (adobe1$Advertisement)
lasttouchchannel_3_Direct = (adobe1$Direct)
lasttouchchannel_3_Messages = (adobe1$Messages)
lasttouchchannel_3_etc = (adobe1$etc)


choice1 = (adobe1$order_yn == 1)
choice2 = (adobe1$order_yn == 2)
table(adobe1$order_yn)

likelihood = function(fc, b)
{

    cc = 1
Cons = b[, cc]; cc = cc + 1
Bday2Specialday = b[, cc]; cc = cc + 1
Bday2Weekdays = b[, cc]; cc = cc + 1
Bhour1A = b[, cc]; cc = cc + 1
Bhour1B = b[, cc]; cc = cc + 1
Bcompany_sizebig = b[, cc]; cc = cc + 1
Bcompany_sizemiddle = b[, cc]; cc = cc + 1
Bretailer_typeApparel = b[, cc]; cc = cc + 1
Bretailer_typeElectronics = b[, cc]; cc = cc + 1
Bretailer_typeGeneral_Merchandise = b[, cc]; cc = cc + 1
Bretailer_typeGroceries = b[, cc]; cc = cc + 1
Bretailer_typeHome_Garden = b[, cc]; cc = cc + 1
Bretailer_typeLuxury = b[, cc]; cc = cc + 1
Bretailer_typeSports_Outdoor = b[, cc]; cc = cc + 1
BmobiledevicetypeEReader = b[, cc]; cc = cc + 1
BmobiledevicetypeGaming_Console = b[, cc]; cc = cc + 1
BmobiledevicetypeMedia_Player = b[, cc]; cc = cc + 1
BmobiledevicetypeMobile_Phone = b[, cc]; cc = cc + 1
BmobiledevicetypePC = b[, cc]; cc = cc + 1
BmobiledevicetypeSet_top_Box = b[, cc]; cc = cc + 1
Blasttouchchannel_3Advertisement = b[, cc]; cc = cc + 1
Blasttouchchannel_3Direct = b[, cc]; cc = cc + 1
Blasttouchchannel_3etc = b[, cc]; cc = cc + 1
Baverage_vvp = b[, cc]; cc = cc + 1
Brevenue = b[, cc]; cc = cc + 1

v1 = Cons * 1 + Bday2Specialday * day2_Specialday + Bday2Weekdays *
day2_Weekdays + Bhour1A * hour1_A + Bhour1B * hour1_B +
Bcompany_sizebig * company_size_big + Bcompany_sizemiddle *
company_size_middle + Bretailer_typeApparel * retailer_type_Apparel +
Bretailer_typeElectronics * retailer_type_Electronics +
Bretailer_typeGeneral_Merchandise * retailer_type_General_Merchandise
+ Bretailer_typeGroceries * retailer_type_Groceries +
Bretailer_typeHome_Garden * retailer_type_Home_Garden +
Bretailer_typeLuxury * retailer_type_Luxury +
Bretailer_typeSports_Outdoor * retailer_type_Sports_Outdoor +
BmobiledevicetypeEReader * mobiledevicetype_EReader +
BmobiledevicetypeGaming_Console * mobiledevicetype_Gaming_Console +
BmobiledevicetypeMedia_Player * mobiledevicetype_Media_Player +
BmobiledevicetypeMobile_Phone * mobiledevicetype_Mobile_Phone +
BmobiledevicetypePC * mobiledevicetype_PC +
BmobiledevicetypeSet_top_Box * mobiledevicetype_Set_top_Box +
Blasttouchchannel_3Advertisement * lasttouchchannel_3_Advertisement +
Blasttouchchannel_3Direct * lasttouchchannel_3_Direct +
Blasttouchchannel_3etc * lasttouchchannel_3_etc + Baverage_vvp *
average_vvp + Brevenue * revenue
v2 = Cons * 1 + Bday2Specialday * day2_Specialday + Bday2Weekdays *
day2_Weekdays + Bhour1A * hour1_A + Bhour1B * hour1_B +
Bcompany_sizebig * company_size_big + Bcompany_sizemiddle *
company_size_middle + Bretailer_typeApparel * retailer_type_Apparel +
Bretailer_typeElectronics * retailer_type_Electronics +
Bretailer_typeGeneral_Merchandise * retailer_type_General_Merchandise
+ Bretailer_typeGroceries * retailer_type_Groceries +
Bretailer_typeHome_Garden * retailer_type_Home_Garden +
Bretailer_typeLuxury * retailer_type_Luxury +
Bretailer_typeSports_Outdoor * retailer_type_Sports_Outdoor +
BmobiledevicetypeEReader * mobiledevicetype_EReader +
BmobiledevicetypeGaming_Console * mobiledevicetype_Gaming_Console +
BmobiledevicetypeMedia_Player * mobiledevicetype_Media_Player +
BmobiledevicetypeMobile_Phone * mobiledevicetype_Mobile_Phone +
BmobiledevicetypePC * mobiledevicetype_PC +
BmobiledevicetypeSet_top_Box * mobiledevicetype_Set_top_Box +
Blasttouchchannel_3Advertisement * lasttouchchannel_3_Advertisement +
Blasttouchchannel_3Direct * lasttouchchannel_3_Direct +
Blasttouchchannel_3etc * lasttouchchannel_3_etc + Baverage_vvp *
average_vvp + Brevenue * revenue

p = (exp(v1) * choice1 + exp(v2) * choice2) / (exp(v1) + exp(v2))

return (p)
}

svN = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0)
gDIST = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1)

control = list(modelname="Multi-level bayesian mixed effect model",
gVarNamesNormal = c("Cons","day2Specialday", "day2Weekdays", "hour1A",
"hour1B", "company_sizebig",
                    "company_sizemiddle", "retailer_typeApparel",
"retailer_typeElectronics",
                    "retailer_typeGeneral_Merchandise",
"retailer_typeGroceries", "retailer_typeHome&Garden",
                    "retailer_typeLuxury",
"retailer_typeSports&Outdoor", "retailer_typeSports&Outdoor",
                    "mobiledevicetypeEReader",
"mobiledevicetypeGaming_Console", "mobiledevicetypeMedia_Player",
                    "mobiledevicetypeMobile_Phone",
"mobiledevicetypePC", "mobiledevicetypeSet_top_Box",
                    "lasttouchchannel_3Advertisement",
"lasttouchchannel_3Direct", "lasttouchchannel_3etc",
                    "Baverage_vvp"),
gVarNamesFixed = c("revenue"),
gDIST = gDIST,
svN = svN,
gNCREP = 1000,
gNEREP = 500,
gNSKIP = 1,
gINFOSKIP = 10,
gSeed = 2016)

model = doHB(likelihood, adobe1, control)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to