class_docstr: # From R
  setwd('c:/workspace')
  data <- read.csv('fair.csv', sep=",")
  
  library(statmod)
  library(tweedie)
  
  model <- glm(affairs ~ rate_marriage + age + yrs_married -1, data=data,
           family=tweedie(var.power=1.5, link.power = 0))
  r <- resid(model, type='response')
  paste(as.character(r[1:17]), collapse=",")
  r <- resid(model, type='deviance')
  paste(as.character(r[1:17]), collapse=",")
  r <- resid(model, type='pearson')
  paste(as.character(r[1:17]), collapse=",")
  r <- resid(model, type='working')
  paste(as.character(r[1:17]), collapse=",")
  paste(as.character(model$coefficients[1:17]), collapse=",")
  s <- summary(model)
  paste(as.character(sqrt(diag(s$cov.scaled))), collapse=",")
  s$deviance
  paste(as.character(model$fitted.values[1:17]), collapse=",")
class_docstr_tok: ["#","From","R","setwd","(","'","c",":","\/workspace","'",")","data","<","-","read.csv","(","'fair.csv","'",",","sep=","''",",","''",")","library","(","statmod",")","library","(","tweedie",")","model","<","-","glm","(","affairs","~","rate_marriage","+","age","+","yrs_married","-1",",","data=data",",","family=tweedie","(","var.power=1.5",",","link.power","=","0",")",")","r","<","-","resid","(","model",",","type='response","'",")","paste","(","as.character","(","r","[","1:17","]",")",",","collapse=","''",",","''",")","r","<","-","resid","(","model",",","type='deviance","'",")","paste","(","as.character","(","r","[","1:17","]",")",",","collapse=","''",",","''",")","r","<","-","resid","(","model",",","type='pearson","'",")","paste","(","as.character","(","r","[","1:17","]",")",",","collapse=","''",",","''",")","r","<","-","resid","(","model",",","type='working","'",")","paste","(","as.character","(","r","[","1:17","]",")",",","collapse=","''",",","''",")","paste","(","as.character","(","model","$","coefficients","[","1:17","]",")",",","collapse=","''",",","''",")","s","<","-","summary","(","model",")","paste","(","as.character","(","sqrt","(","diag","(","s","$","cov.scaled",")",")",")",",","collapse=","''",",","''",")","s","$","deviance","paste","(","as.character","(","model","$","fitted.values","[","1:17","]",")",",","collapse=","''",",","''",")"]
code: def __init__(self):
      resid_resp = [
          -0.997868449815039,
          2.69283106662728,
          0.677397439981157,
          0.220024942629269,
          4.30244966465517,
          4.12917275616972,
          0.669303122309246,
          1.64321562230925,
          3.73361710426128,
          0.271937359562684,
          1.70030700747884,
          1.55430573164611,
          -0.263723852468304,
          1.51263973164611,
          2.75223392654071,
          0.310487741565721,
          1.28077676333896,
          -0.722602160018842,
      ]
      resid_dev = [
          -1.40274708439925,
          2.48476334070913,
          0.722690630291423,
          0.333179337353702,
          4.00781035212304,
          3.33344591331998,
          1.51543361886727,
          2.82502498800952,
          2.2795411865605,
          0.245239170945663,
          0.993721205729013,
          1.74920359743562,
          -0.363141475997386,
          1.71412357710318,
          2.57445879456298,
          0.279858474280908,
          1.22953362433333,
          -1.84397406923697,
      ]
      resid_pear = [
          -0.923380371255914,
          4.28706294677515,
          0.864309147553743,
          0.366063826152319,
          9.17690493704408,
          6.57783985712941,
          2.39340023647571,
          5.87607098775551,
          3.55791152198837,
          0.260052421285998,
          1.21439278430259,
          2.66470328868695,
          -0.327698246542009,
          2.59327105694137,
          4.53096038849505,
          0.299198418236691,
          1.6399313081981,
          -0.921987034618483,
      ]
      resid_work = [
          -0.899807800767353,
          5.00583784559752,
          0.937441759049674,
          0.433762277766879,
          11.8128959278604,
          7.6822784352496,
          3.65998654763585,
          8.98568506862295,
          3.50120010377224,
          0.256207345500911,
          1.08551656668241,
          3.18923357641756,
          -0.352302468597673,
          3.10374035363038,
          5.35005901385941,
          0.29552727652976,
          1.78077778644209,
          -1,
      ]
      self.resid_response = resid_resp
      self.resid_deviance = resid_dev
      self.resid_working = resid_work
      self.resid_pearson = resid_pear
      # self.null_deviance = 3731.85161919 # N/A
      self.params = [
          -0.389168171340452,
          0.0670222370664611,
          -0.0970852004566712,
      ]
      self.bse = [
          0.0323435784513691,
          0.0063805300018014,
          0.00893580175352525,
      ]
      # self.aic_R = 522.14215776 # R adds 2 for dof to AIC
      # self.aic_Stata = 7.459173652869477  # stata divides by nobs
      # self.deviance = 70.6652992116034   # from Stata
      self.deviance = 20741.82  # from R
      # self.scale = 1.0
      # self.llf = -250.0710778504317  # from Stata, ours with scale=1
      # self.bic_Stata = -179.9959200693088  # no bic in R?
      self.df_model = 2
      self.df_resid = 6363
  
      # TODO: taken from Stata; not available in sm yet
      # self.chi2 = 2699.138063147485
  
      self.fittedvalues = [
          1.10897954981504,
          0.537938133372725,
          0.722602160018842,
          0.507247757370731,
          0.364216335344828,
          0.537493243830281,
          0.182870377690754,
          0.182870377690754,
          1.06638209573872,
          1.06139564043732,
          1.56635749252116,
          0.487360268353893,
          0.748572252468304,
          0.487360268353893,
          0.514430573459285,
          1.05062295843428,
          0.71922323666104,
          0.722602160018842,
      ]
  
imports: import os
  import numpy
  import pandas
  from statsmodels.api import add_constant
  from statsmodels.genmod.tests.results import glm_test_resids
label_desc: Use image node_id 1 to create a new FairTweedieLog15 object  with example: obj = FairTweedieLog15()