Chris,
Thanks for the quick response. Why don't I start with a simple example
using linear regression. In the examples there is a model called
"Simple Pricing Model". I have copied it below, and added a simple
weighting function. I want to solve the simple equation y = a + b*x,
but I want to weight it with the weight array I defined below (where
there is almost no weight on the first x,y pair and full weight on the
last (linear slope in between). In R I would simply call the function
lm by:
results = lm(price~age, weight=weight)
This will minimize the Sum(weights * Residuals**2). I could code this
from scratch where I find the weighted mean for age & price, and then
find the residuals, then multiply the weights by the residuals. This
is quite common in regression and we use it all the time to weight
more recent events more heavily than old ones.
So how could I modify the code below to incorporate the weights array
I defined? I thought using a Potential variable would do it, but I
can't find any examples anywhere. The text in the User's Guide helps
to explain the purpose of Potentials, but doesn't show how to use
them.
Thanks again,
Gary Post
______________________
from pymc import *
from numpy import *
# Data
age = array([13, 14, 14,12, 9, 15, 10, 14, 9, 14, 13, 12, 9, 10, 15,
11, 15, 11, 7, 13, 13, 10, 9, 6, 11, 15, 13, 10, 9, 9, 15, 14, 14, 10,
14, 11, 13, 14, 10])
price = array([2950, 2300, 3900, 2800, 5000, 2999, 3950, 2995, 4500,
2800, 1990, 3500, 5100, 3900, 2900, 4950, 2000, 3400, 8999, 4000,
2950, 3250, 3950, 4600, 4500, 1600, 3900, 4200, 6500, 3500, 2999,
2600, 3250, 2500, 2400, 3990, 4600, 450,4700])/1000.
weight = array([i/float(sum(range(len(age)))) for i in
range(len(age))])
# Constant priors for parameters
a = Normal('a', 0, 0.0001)
b = Normal('b', 0, 0.0001)
# Precision of normal distribution of prices
tau = Gamma('tau', alpha=0.1, beta=0.1)
@deterministic
def mu(x=age, a=a, b=b):
# Linear age-price model
return a + b*x
# Sampling distribution of prices
p = Normal('p', mu, tau, value=price, observed=True)
On Sep 24, 9:39 am, Chris Fonnesbeck <
fonnesb...@gmail.com> wrote:
> On Sep 23, 9:04 am, Postman <
postman...@gmail.com> wrote:
>
> > I'm new to the group and am doing some sports modeling using pymc. I
> > was able to replicate the WinBUGS code in this paper:
http://www.statistica.it/gianluca/BaioBlangiardo.pdfbutwant to