English 中文(简体)
发言时间 RFunction in python
原标题:Imitating ppoints R function in python
  • 时间:2013-11-29 19:10:13
  •  标签:
  • python
  • r

http://www.un.org/Depts/DGACM/index_russian.htm

Ordinates for Probability Plotting

Description:

     Generates the sequence of probability points ‘(1:m - a)/(m +
     (1-a)-a)’ where ‘m’ is either ‘n’, if ‘length(n)==1’, or
     ‘length(n)’.

Usage:

     ppoints(n, a = ifelse(n <= 10, 3/8, 1/2))
...

我曾试图在<代码>python上复制这一功能,我有两点怀疑。

1- The first m in (1:m - a)/(m + (1-a)-a) is persistent an integer: int(n) (e:the integer of >?

2- The second m in the sameality is NOT an integer if length (n)==1 (它承担<代码>n和 a integer (length(n))其他用途。

3- The n in a = 如果else(n <= 10, 3/8, 1/2) is the real number n if length(n)==1 and the integer >codelength(n) otherwise.

描述中根本没有阐明这一点,我非常赞赏有人能够证实情况确实如此。


Add

最初张贴在https://stats.stackchange.com/。 因为我希望得到与<代码>ppoints功能有关的静态人员的投入。 自我迁出后,我写到以下职能之后,复制了<代码>ppoints,载于python。 我对此进行了测试,而且这两种结果似乎都回过头来,但如果有人能够澄清上述要点,因为职能说明根本不明确。

def ppoints(vector):
       
    Mimics R s function  ppoints .
       

    m_range = int(vector[0]) if len(vector)==1 else len(vector)

    n = vector[0] if len(vector)==1 else len(vector)
    a = 3./8. if n <= 10 else 1./2

    m_value =  n if len(vector)==1 else m_range
    pp_list = [((m+1)-a)/(m_value+(1-a)-a) for m in range(m_range)]

    return pp_list
最佳回答

我将怀着:壮志执行:

import numpy as np
def ppoints(n, a):
    """ numpy analogue or `R` s `ppoints` function
        see details at http://stat.ethz.ch/R-manual/R-patched/library/stats/html/ppoints.html 
        :param n: array type or number"""
    try:
        n = np.float(len(n))
    except TypeError:
        n = np.float(n)
    return (np.arange(n) + 1 - a)/(n + 1 - 2*a)

样本产出:

>>> ppoints(5, 1./2)
array([ 0.1,  0.3,  0.5,  0.7,  0.9])
>>> ppoints(5, 1./4)
array([ 0.13636364,  0.31818182,  0.5       ,  0.68181818,  0.86363636])
>>> n = 10
>>> a = 3./8. if n <= 10 else 1./2
>>> ppoints(n, a)
array([ 0.06097561,  0.15853659,  0.25609756,  0.35365854,  0.45121951,
        0.54878049,  0.64634146,  0.74390244,  0.84146341,  0.93902439])

人们可以使用用于测试实施情况。

问题回答

R 帮助指(测试):

ppoints <- function(n) {
  if (is.array(n)) {
    m <- as.numeric(length(n))
  } else {
    m <- as.numeric(n)
  }
  a = if (m <= 10) 3/8 else 1/2
  return((seq_len(m)  - a) / (m + 1 - 2*a))
}




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...