0

I am currently using R studio, and downloaded the 'brms' package, for those who are familiar with it. I wanted to create a code which loaded a data set, ran a poisson transformation on it, and coded the transformation as a different variable:

`install.packages("brms")
library(brms)
#In this example, we have a data set which includes data for fishing,
#like number of fish caught, whether bait was used, etc.
#We will bit this using something called a 'zero limit possion' model'.
zinb <- read.csv("http://stats.idre.ucla.edu/stat/data/fish.csv") #data set
zinb$camper <- factor(zinb$camper, labels = c("no", "yes")) #adding whether camper was there
head(zinb)
is.data.frame(zinb)
summary(zinb)
#below, we fit our zinb data set into that zero limit possion model, and
#our predictors will be number of persons, whether there was a child,
#and if the group consisted of campers. 
fit_zinb1=brm(data=zinb, count ~persons + child + camper,
             family = zero_inflated_poisson("log")) #specify the data, and the family

#see what it looks like
summary(fit_zinb1)

However, R fails to recognize my new variable "fit_zinb1". Any thoughts as to why this might be the case?

Thank you so much!

aiyer1217
  • 1
  • 1
  • 2
    Your code runs fine for me. What error message do you receive? – Dan Nov 27 '18 at 15:26
  • From your statement, "R fails to recognize my new variable fit_zinb1" I'm assuming you are looking for some sort of numeric return. A feature of R is that (almost) without exception, functions return objects, not values. In fact R was originally S which was written to accommodate statisticians. Specifically, the output of the brm object is not a vector. – meh Nov 27 '18 at 16:04
  • You can use summary() and str() to explore what the outputs are, and most specifically what ever is the data you want to call the fit_znb1 variable. – meh Nov 27 '18 at 16:04
  • @aginensky The OP already uses `summary` in an effort to view `fit_zinb1`. – Dan Nov 27 '18 at 16:59

1 Answers1

1

Thanks for your question. Your code runs fine and gives the output below.

Which probably means you're system is not set up properly to run library(brms). Have you tried running a simple model in library(rstan)? The eight schools model from here for instance: https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started

It will likely not run and may give you some a better idea of what is missing from your set-up to run these models.

Family: zero_inflated_poisson 
Links: mu = log; zi = identity 
Formula: count ~ persons + child + camper 
Data: zinb (Number of observations: 250) 
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
     total post-warmup samples = 4000

Population-Level Effects: 
          Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept    -1.01      0.17    -1.33    -0.66       2684 1.00
persons       0.87      0.04     0.79     0.96       2678 1.00
child        -1.37      0.09    -1.55    -1.19       2890 1.00
camperyes     0.79      0.09     0.61     0.98       3329 1.00

Family Specific Parameters: 
   Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
zi     0.41      0.04     0.32     0.50       3071 1.00

Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample 
is a crude measure of effective sample size, and Rhat is the potential 
scale reduction factor on split chains (at convergence, Rhat = 1).
Ewen
  • 1,276
  • 8
  • 13
  • No problem. If this has helped, please up vote answer +/- accept. Thank you! https://stackoverflow.com/help/someone-answers – Ewen Nov 29 '18 at 06:12