frequency-distribution

How can I optimize a two variable function in R

纵饮孤独 提交于 2020-05-29 11:45:09
问题 I have been trying to optimize the following function, but without success: parametros <- data.frame(ap=c(11.1,7.07,6.3,4.75,4,3.35), fx=c(41.2012,39.3732,25.2912,10.3455,1.2253,0.4017)) xm<-11.2 fxcalc <- function(s,t){(1-(1-(parametros$ap/xm)^(s))^t)*100} suma <- function(s,t){(parametros$fx-fxcalc(s,t))^2} func <- function(s,t){sum(suma(s,t))} Being "func()" the function I am trying to minimize for "s" and "t". Apparently the function "optim()" wouldn't work with more than one variable.

How can I optimize a two variable function in R

与世无争的帅哥 提交于 2020-05-29 11:44:05
问题 I have been trying to optimize the following function, but without success: parametros <- data.frame(ap=c(11.1,7.07,6.3,4.75,4,3.35), fx=c(41.2012,39.3732,25.2912,10.3455,1.2253,0.4017)) xm<-11.2 fxcalc <- function(s,t){(1-(1-(parametros$ap/xm)^(s))^t)*100} suma <- function(s,t){(parametros$fx-fxcalc(s,t))^2} func <- function(s,t){sum(suma(s,t))} Being "func()" the function I am trying to minimize for "s" and "t". Apparently the function "optim()" wouldn't work with more than one variable.

Calculating the standard deviation from columns of values and frequencies in Power BI

喜你入骨 提交于 2020-02-04 03:34:45
问题 I am trying to calculate the standard deviation of a set of values in PowerBI and I am stuck. There are two columns in a table (days and count). This is a frequency distribution of a transportation lane. Days goes from 1 to 100, count is the number of shipments that took those number of days. The formula to calculate the standard deviation of a frequency distribution is pretty straight forward: sqrt(sum(fx * (x - avgx)^2))/sum(fx)) But the Dax is giving me a massive headache. Any help would

Calculating frequency distribution of a collection with .Net/C#

*爱你&永不变心* 提交于 2020-01-15 05:31:13
问题 Is there a fast/simple way to calculate the frequency distribution of a .Net collection using Linq or otherwise? For example: An arbitrarily long List contains many repetitions. What's a clever way of walking the list and counting/tracking repetitions? 回答1: The easiest way is to use a hashmap and either use the value as the key and increment the value, or pick a bucket size (bucket 1 = 1 - 10, bucket 2 = 11 - 20, etc), and increment each bucket by the value. Then you can go through and

Interpret numpy.fft.fft2 output

老子叫甜甜 提交于 2020-01-02 01:55:06
问题 My goal is to obtain a plot with the spatial frequencies of an image - kind of like doing a fourier transformation on it. I don't care about the position on the image of features with the frequency f (for instance); I'd just like to have a graphic which tells me how much of every frequency I have (the amplitude for a frequency band could be represented by the sum of contrasts with that frequency). I am trying to do this via the numpy.fft.fft2 function. Here is a link to a minimal example

Frequency tables with weighted data in R

孤街醉人 提交于 2020-01-01 04:25:10
问题 I need to calculate the frequency of individuals by age and marital status so normally I'd use: table(age, marital_status) However each individual has a different weight after the sampling of the data. How do I incorporate this into my frequency table? 回答1: You can use function svytable from package survey , or wtd.table from rgrs . EDIT : rgrs is now called questionr : df <- data.frame(var = c("A", "A", "B", "B"), wt = c(30, 10, 20, 40)) library(questionr) wtd.table(x = df$var, weights = df

Calculating grouped variance from a frequency table in R

北慕城南 提交于 2019-12-31 03:46:11
问题 How can I, in R calculate the overall variance and the variance for each group from a dataset that looks like this (for example): Group Count Value A 3 5 A 2 8 B 1 11 B 3 15 I know to calculate the variance as a whole, ignoring the groups I would do: var(rep(x$Value, x$Count)), but how do I automatically calculate the variance for each group accounting for the frequency? E.g., the variance for group A, group B, etc.,.. I would like my output to have the following headers: Group, Total Count,

R Count of strings by two factors

偶尔善良 提交于 2019-12-24 10:09:05
问题 I need some help. I have the following table: country_code=c(1,1,1,1,1,1,2,2,2,2,2,2) target=c('V1','V1','V2','V2','V3','V3','V1','V1','V2','V2','V3','V3') M1=c('X7','X7','X14','X14','X8','X8','X29','X22','X2','X22','X22','X22') M2=c('X1','X1','X17','X11','X21','X21','X1','X29','X8','X18','X24','X24') M3=c('NA','NA','NA','X1','NA','NA','NA','NA','NA','NA','NA','NA') CountofRun=c(1,2,1,2,1,2,1,2,1,2,1,2) df<-data.frame(country_code,target,M1,M2,M3,CountofRun) and I would like to get a

Frequency of elements in matrix - Matlab

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 14:09:10
问题 From a function that i run in matlab i get a 225x400 matrix. I want to count the frequency of each element in this matrix, meaning that i need to calculate how many times each elements appears on the the matrix. My matrix name is "Idiff" I am using: B=unique(Idiff); to find the unique elements in the Idiff matrix. I receive a column of 1138 elements, so i understand that these elements are unique and all the other elements in the Idiff matrix are these elements repeated. Now i try to count

Random numbers that follow a linear drop distribution in Python

流过昼夜 提交于 2019-12-13 09:45:31
问题 I'd like to generate random numbers that follow a dropping linear frequency distribution, take n=1-x for an example. The numpy library however seems to offer only more complex distributions. 回答1: So, it turns out you can totally use random.triangular(0,1,0) for this. See documentation here: https://docs.python.org/2/library/random.html random.triangular(low, high, mode) Return a random floating point number N such that low <= N <= high and with the specified mode between those bounds.