How to find the equation of a curve given the data set (x,y) in VB.net? - 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.

Related

How to zoom in data points without changing x values?

I have four sets of data which have been created in dictionaries. After plotting them in one graph it is hard to clearly differentiate the point.
I put all of the data frames in one graph. My intention is to zoom in data points without changing x values that one can see the difference.
Please, help me in this regard. Thank you!
Graph Describes 4 sets of data

Stata output variable to matrix with ebalance

I'm using the ebalance Stata package to calculate post-stratification weights, and I'd like to convert the weights output (_webal, which is generated as a double with format %10.0g) to a matrix.
I'd like to normalize all weights in the "control" group, but I can't seem to convert the variable to a matrix in order to manipulate the weights individually (I'm a novice to Stata, so I was just going to do this using a loop––I'd normally just export and do this in R, but I have to calculate results within a bootstrap). I can, however, view the individual-level weights produced by the output, and I can use them to calculate sample statistics.
Any ideas, anyone? Thanks so much!
This is not an answer, but it doesn't fit within a comment box.
As a self-described novice in Stata, you are asking the wrong question.
Your problem is that you have a variable that you want to do some calculations on, and since you can't just use R and you don't know how to do those (unspecified) calculations directly in Stata, you have decided that the first step is to create a matrix from the variable.
Your question would be better phrased as a simple description of the relevant portions of your data and the calculation you need to do using that data (ebalance is an obscure distraction that probably lost you a few readers) and where you are stuck.
See also https://stackoverflow.com/help/mcve for a discussion of completing a minimal complete example with a description of the results you expect for that example.

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.

Equation for Length of Cubic Spline Between 3 Points

This is my first time posting here, so I hope this is ok. I'm working on a java project but my question is really about the math I'll be using for it...
I have three (different) points at (x1, y1), (x2, y2), and (x3, y3). All I need is a formula for the length of the cubic spline formed between them. For someone good at calculus, this should be pretty easy to derive. I've looked all around online but can't seem to find the solution. Again, I don't even need the equation of the spline - just its length, given the three points. Thanks in advance! If someone can figure this out and share, you'll makey day :)
I have some bad news.
The first is that a cubic b-spline generally takes 4 points to define. It is possible to define one from 3 points, but it usually involves making up another point somehow (for example, using degree elevation). So we'd need to have information about how exactly you're defining the spline - if it's some other kind of spline (catmull-rohm?), or the details of how you're constructing it.
The second is that there's no closed-form equation for the length of a b-spline, or even a Bezier curve. What I typically do is sample the curve at a lot of points, and then compute the length of the polyline.
There are formulas that can tell you what your error bound will be, based on the derivatives of the curve, and there are methods that approximate using arcs rather than line segments, but those are probably more complicated than they're worth.
See the primer on bezier curves for a more info. However, sadly, tfinniga is correct for cubic splines you need to use an approximation.

How to plot a Pearson correlation given a time series?

I am using the code in this website http://blog.chrislowis.co.uk/2008/11/24/ruby-gsl-pearson.html to implement a Pearson Correlation given two time series data like so:
require 'gsl'
pearson_correlation = GSL::Stats::correlation(
GSL::Vector.alloc(first_metrics),GSL::Vector.alloc(second_metrics)
)
This returns a number such as -0.2352461593569471.
I'm currently using the highcharts library and am feeding it two sets of timeseries data. Given that I have a finite time series for both sets, can I do something with this number (-0.2352461593569471) to create a third time series showing the slope of this curve? If anyone can point me in the right direction I'd really appreciate it!
No, correlation doesn't tell you anything about the slope of the line of best fit. It just tells you approximately how much of the variability in one variable (or one time series, in this case) can be explained by the other. There is a reasonably good description here: http://www.graphpad.com/support/faqid/1141/.
How you deal with the data in your specific case is highly dependent on what you're trying to achieve. Are you trying to show that variable X causes variable Y? If so, you could start by dropping the time-series-ness, and just treat the data as paired values, and use linear regression. If you're trying to find a model of how X and Y vary together over time, you could look at multivariate linear regression (I'm not very familiar with this, though).