gamma-distribution

Function that will generate iter samples of size n from a gamma distribution with shape parameter alpha and rate parameter beta

…衆ロ難τιáo~ 提交于 2020-01-25 08:34:06
问题 The function needs to return the mean and standard deviation of each sample. This is what I have: sample_gamma <- function(alpha, beta, n, iter) { mean = alpha/beta var = alpha/(beta)^2 sd = sqrt(var) gamma = rgamma(n,shape = alpha, scale = 1/beta) sample_gamma = data.frame(mean = replicate(n = iter, expr = mean)) } I'm very lost for this. I also need to create a data frame for this function. Thank you for your time. Edit: sample_gamma <- function(alpha, beta, n, iter) { output <- rgamma(iter

Trying to iterate my function many times using i

十年热恋 提交于 2020-01-25 07:05:18
问题 I'm trying to iterate a for loop many times but it's only printing out once. sample_gamma <- function(alpha, beta, n, iter) { mean_s = c() mean_sd = c() for(i in 1:iter){ a = rgamma(n, shape = alpha, scale = 1/beta) return(c(mean(a), sd(a))) } 回答1: i think you are looking for this sample_gamma <- function(alpha, beta, n, iter) { mean_s = c() mean_sd = c() for(i in 1:iter){ a = rgamma(n, shape = alpha, scale = 1/beta) print(c(mean(a), sd(a))) } } 来源: https://stackoverflow.com/questions

Gamma distribution fit error

谁说我不能喝 提交于 2020-01-22 02:29:25
问题 For a classification task I want to fit a gamma distribution to two pair of data: Distance population within class and between class. This is to determine the theoretical False Accept and False Reject Rate. The fit Scipy returns puzzles me tough. A plot of the data is below, where circles denote within class distances and x-es between class distance, the solid line is the fitted gamma within class, the dotted line is the fitted gamma on the between class distance. What I would have expected

Fitting parameter b of the Gamma distribution from mean, 95% in Python

白昼怎懂夜的黑 提交于 2020-01-15 10:13:09
问题 This Mathematica function finds parameter b of the Gamma distribution, given mean and 95% values and scaled by the mean [Mu]; The two values bracket [Beta] makes it fast and there is a restriction for max pg95= 5.8[Mu]* gb[[Mu] , p95 ]. I need to translate this code into Python: gb[\[Mu]_, p95_] := Block[{p = Min[p95/\[Mu], 5.8]}, \[Mu] FindRoot[CDF[GammaDistribution[1/\[Beta], \[Beta]], p] - .95 == 0, {\[Beta], 1, If[p == 1, 1.1, p]}][[1, 2]]]; 回答1: Even if you cannot find exactly equivalent

How would you fit a gamma distribution to a data in R?

柔情痞子 提交于 2020-01-01 03:51:39
问题 Suppose I have the variable x that was generated using the following approach: x <- rgamma(100,2,11) + rnorm(100,0,.01) #gamma distr + some gaussian noise head(x,20) [1] 0.35135058 0.12784251 0.23770365 0.13095612 0.18796901 0.18251968 [7] 0.20506117 0.25298286 0.11888596 0.07953969 0.09763770 0.28698417 [13] 0.07647302 0.17489578 0.02594517 0.14016041 0.04102864 0.13677059 [19] 0.18963015 0.23626828 How could I fit a gamma distribution to it? 回答1: A good alternative is the fitdistrplus

Matlab gamfit and gampdf functions written in C++

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:22:29
问题 I am wondering if someone has already implemented the two Matlab functions gamfit and gampdf in C, C++ or objective-C. I figured I would ask before I go ahead and implement them myself. 回答1: Hope those links to c source code may be of help: http://www.mymathlib.com/functions http://www.mymathlib.com/functions/probability/gamma_distribution.html http://www.mymathlib.com/c_source/functions/probability/densities/gamma_density.c Note: You should check for license, only reference I could find

How can I estimate the shape and scale of a gamma dist. with a particular mean and a 95% quantile?

倾然丶 夕夏残阳落幕 提交于 2019-12-23 12:26:50
问题 Is there any way, in R, to calculate the scale and shape of a gamma distribution, given a particular value of mean (or median) and a particular quantile (the 95% quantile)? So for example I have a mean = 130 and a 95% quantile = 300 with an offset of the distribution at 80 is there any way to obtain the scale and shape of a gamma that meet these criteria? 回答1: Here is one approach: myfun <- function(shape) { scale <- 130/shape pgamma(300, shape, scale=scale) - 0.95 } tmp <- uniroot( myfun,

Gamma Distribution in Boost

允我心安 提交于 2019-12-22 19:41:51
问题 I'm trying to use the Gamma distribution from boost::math but it looks like it isn't possible to use it with boost::variate_generator. Could someone confirm that? Or is there a way to use it. I discovered that there is a boost::gamma_distribution undocumented that could probably be used too but it only allows to choose the alpha parameter from the distribution and not the beta. Thanks! 回答1: As mentioned in this link, you can extend Boost's (or TR1's) one-parameter gamma distribution simply by

R: coding why show 0.00 in result

自古美人都是妖i 提交于 2019-12-12 02:54:12
问题 My aims of this simulation is to evaluate the type 1 error rate of the tests under several combination of factors. sample sizes-(10,10),(10,25),(25,25),(25,50),(25,100),50,25),(50,100), (100,25),(100,100) standard deviation ratio- (1.00, 1.50, 2.00, 2.50, 3.00 and 3.50) distribution of gamma distribution with unequal skewness and equal skewness The 2 sample test involved are pooled variance t test and welch t test and mann whitney test. I tried to modified a code by using the above

Using python scipy to fit gamma distribution to data

给你一囗甜甜゛ 提交于 2019-12-10 14:58:15
问题 I want to fit a gamma distribution to my data, which I do using this import scipy.stats as ss import scipy as sp import numpy as np import os import matplotlib.pyplot as plt alpha = [] beta = [] loc = [] data = np.loadtxt(data) fit_alpha, fit_loc, fit_beta = ss.gamma.fit(data, floc=0, fscale=1) I want to keep one of the parameters to the gamma distribution as a variable (say the shape), and fix one of the parameters (say scale=1 ). However, if I keep the loc variable as zero, I am not able to