hurdle_test: hurdle_test

Description Usage Arguments Details Value

View source: R/main.R

Description

hurdle_test performs a hurdle test and returns multiple test statstics given a variable y and a variable x. Hurdle test can be used to fit a linear model when a data set contains excess amount of zeros.

Usage

1
2
3
4
5
6
7
8
hurdle_test(
  y_var,
  x_var,
  zero_fam = "binomial",
  count_dist = "negbin",
  zero_dist = "binomial",
  link = "logit"
)

Arguments

y_var

a vector of numeric representing the y variable

x_var

a vector of numeric representing the x variable

zero_fam

a character representing the model family for the zero portion of the data. Defaulted to "binomial" indicating binomial family

count_dist

a character representing the distribution to the count distribution. Defaulted to 'negbin' indicating the negative binomial distribution

zero_dist

a character representing the distribution to the zero distribution. Defaulted to "binomial" indicating the binomial distribution

link

a character representing the link function. Defaulted to 'logit' meaning logarithm link function

Details

The hurdle test deal with zero and non-zero portion separatly using two different models, using negative binomial distribution for the non-zero portion and binomial distribution for the zero portion. Confident intervals are created correspondingly to measure the level of confidence against the trend. A glm will be then established with a logarithm link function. The slope and intercept of the resulting model will be recorded and returned. Things to take notice of: 1. y and x need to have the same length 2. Although the detail section only describes the condition with negbin count distribution binomial zero distribution, this function can be used for other distributions as well. Do note that this function does not checks for the accuracy of the fitted model, neither does it provide any recommandations to what distribution fits the best. In order to use other families, it is highly suggested to look at the concept of general linear beforehands. 3. The program will return an error if the x variable does not contain any zeros. In order to calculate the trend using this function, do make sure that there is zero values in the x variable. If the error message "Data cannot be fitted using hurdle model" appears, user might want to consider using plain negative binomial model(provided in the negbin() function in the same package) for cases with excess amount of zeros, or Mann-Kendall Test for cases with limited ties and zeros.

Value

a dataframe of the form || slope || intercept || ConfidenceLevel ||, or a character if the test is not applicable;


sarahforte/CESIfun documentation built on Dec. 22, 2021, 10:16 p.m.