Spline smoothing and Extrapolation for cumulative density function - smoothing

I would like to smooth an empirical survival function using splines and then extrapolate the function for larger values of elapsed time (x values), so with an asymptote to 0. With monotone splines (like scipy.interpolate.PchipInterpolator) it seems not possibile. I would like to obtain something like this (picture). Can anyone help me?
Thank you very much!
enter image description here

Related

bridgesampling with data from R2OpenBugs

I am working on Bayesian Model Averaging and need to calculate posterior model probabilities.
I want to use `bridge sampling' method recommended by Meng and Wong (1996) and Lopes and West (2004). I have posterior sample as mcmc.list class that I obtained using R2OPenBugs (90,000 samples, each sample has four values). To approximate the marginal likelihood, an approximation function g() to the joint posterior density is chosen. For simplicity, we
took g() as the tetravariate normal density function with mean set to the empirical mean
vector and variance set to the empirical variance-covariance matrix from the mcmc sample.
I dont know how to code in R this function nor how to use existing bridge_sampler function.
Bridge_sampler function has arguments that I dont know what they mean. Tutorial gives example how to use bridge_sampler function with jugs data but not with R2OpenBugs data.
Any help is appreciated!

Monte Carlo Integration

Does anyone have any ideas how to implement a monte carlo integration simulator in vb.net.
I have looked around the internet with no luck.
Any code, or ideas as to how to start it would be of help.
Well i guess we are talking about a 2 dimensional problem. I assume you have a polygon of which you want to calculate the area.
1) First you need a function to check if a point is inside the polygon.
2) Now you define an area with a known size around the polygon.
3) Now you need random points inside your known area, some of them will be in your polygon, some will be outside, count them!
4) Now you have two relations: First the relations of all points to points inside your polygon. Second the area around your polygon which you know, to the area of the polygon you don't know.
5) The relations is the same --> you can calculate the area of your polygon! (Area of polygon should be: points in you polygon / all your points * size of known area)
Example: 3 points hits hit the polygon, 20 points where "shot", the area of the polygon is 0.6m²
NOTE: This area is only an approach! The more points you have, the better the approach gets.
You can implement a fancy method to display this in your vb program of course. Was this what you needed? Is my assumption about the polygon correct? Do you need help with the "point inside polygon" algorithm?
There is nothing specific to VB.net with this problem, except maybe for the choice of a random number generator from the library.
Numerically solving integrals of a function f(x_1,...,x_n) by using can become infeasible (in acceptable time) for high dimensions n, because the number of sample points needed for a given sampling distance grows exponentially with the dimension of the problem. The fundamental idea with Monte Carlo Integration is to replace the uniform sampling of the variables x_1,...,x_n with random sampling, taking n random numbers per sample. With these samples, estimate the integral. The more samples, the better the estimate. And the major benefit of MC integration is, that you can use standard statistical methods to estimate the error of your result.
So, how to start: Implement integration by uniform sampling of the integration space, then go to random sampling and add error estimation.

Fitting curves to a set of points

Basically, I have a set of up to 100 co-ordinates, along with the desired tangents to the curve at the first and last point.
I have looked into various methods of curve-fitting, by which I mean an algorithm with takes the inputted data points and tangents, and outputs the equation of the cure, such as the gaussian method and interpolation, but I really struggled understanding them.
I am not asking for code (If you choose to give it, thats acceptable though :) ), I am simply looking for help into this algorithm. It will eventually be converted to Objective-C for an iPhone app, if that changes anything..
EDIT:
I know the order of all of the points. They are not too close together, so passing through all points is necessary - aka interpolation (unless anyone can suggest something else). And as far as I know, an algebraic curve is what I'm looking for. This is all being done on a 2D plane by the way
I'd recommend to consider cubic splines. There is some explanation and code to calculate them in plain C in Numerical Recipes book (chapter 3.3)
Most interpolation methods originally work with functions: given a set of x and y values, they compute a function which computes a y value for every x value, meeting the specified constraints. As a function can only ever compute a single y value for every x value, such an curve cannot loop back on itself.
To turn this into a real 2D setup, you want two functions which compute x resp. y values based on some parameter that is conventionally called t. So the first step is computing t values for your input data. You can usually get a good approximation by summing over euclidean distances: think about a polyline connecting all your points with straight segments. Then the parameter would be the distance along this line for every input pair.
So now you have two interpolation problem: one to compute x from t and the other y from t. You can formulate this as a spline interpolation, e.g. using cubic splines. That gives you a large system of linear equations which you can solve iteratively up to the desired precision.
The result of a spline interpolation will be a piecewise description of a suitable curve. If you wanted a single equation, then a lagrange interpolation would fit that bill, but the result might have odd twists and turns for many sets of input data.

How to find the equation of a curve given the data set (x,y) in VB.net?

I am new to VB.NET and I am trying to write code in vb.net to find a equation when data points are given. For example (1,5),(2,6) etc.
I need to find a equation(not necessarily always linear) from the given points.
I tried to use the help given in
How do I calculate a trendline for a graph?
but couldn't figure out how to get equation.
Any help will be highly appreciated.
Thanks in advance.
What you're looking for is called Interpolation
Basically it's a field in numerical analysis, and it helps you create a polynomial representation of the data points.

Quadratic Bezier Curve: Calculate Tangent

I have a quadratic bezier curve and I want to calculate the slope of the tangent in a given point. For example, let it be the middlepoint of the quadratic bezier curve, therefore t=0.5 (please see the link below for a picture of this). I've calculated the first derivative of the formula for the quadratic bezier curve; however I get 400 as value for the slope, though it should be 0. Maybe I'm using the first derivative in a wrong way? I know I could also calculate the tangents using trigonometric functions; however I'd like to do it using the first derivative, shouldn't this be possible? Thanks for any hint!
For clarification / please note: I'm interested in a general way to get the slope in a arbitrary given point on a quadratic bezier curve, not only to get the tangent in the start- and end point.
A picture of my problem including the text above:
http://cid-0432ee4cfe9c26a0.skydrive.live.com/self.aspx/%c3%96ffentlich/Quadratic%20Bezier%20Curve.pdf
Thank you very much for any hint!
Using your formula for B'(t), evaluated at t=1/2, we get
B'(1/2) = -P0 + P2
From the look of your graph, P0 = (0,0) and P2 = (400,0). So
B'(1/2) = (400,0).
This is the "velocity" of a point traveling along B(t) at t=1/2.
(400,0) is a horizontal vector, with magnitude 400.
So all is as it should be. Since B'(t) is horizontal, it does have "slope" 0.
Derivatives of a Bézier Curve