## Call R (programming language) from .net

R.NET is pretty buggy with the newer version of R. And if it doesn’t work right, it works terribly (and will continue to do so unless you know exactly how to fix it). Personally, I’d recommend using R script files and executing them. What you should do is start your R script with > sink() … Read more

## Fitting polynomials to data

Thanks for everyone’s replies. Here is another attempt at summarizing them. Pardon if I say too many “obvious” things: I knew nothing about least squares before, so everything was new to me. NOT polynomial interpolation Polynomial interpolation is fitting a polynomial of degree n given n+1 data points, e.g. finding a cubic that passes exactly … Read more

## Plotting a 3D surface plot with contour map overlay, using R

Edit: I just saw that you pointed out one of your dimensions is a date. In that case, have a look at Jeff Ryan’s chartSeries3d which is designed to chart 3-dimensional time series. Here he shows the yield curve over time: Original Answer: As I understand it, you want a countour map to be the … Read more

## Using cbind on an arbitrarily long list of objects

The do.call function is very useful here: A <- 1:10 B <- 11:20 C <- 20:11 > do.call(cbind, list(A,B,C)) [,1] [,2] [,3] [1,] 1 11 20 [2,] 2 12 19 [3,] 3 13 18 [4,] 4 14 17 [5,] 5 15 16 [6,] 6 16 15 [7,] 7 17 14 [8,] 8 18 13 [9,] … Read more

## confidence and prediction intervals with StatsModels

For test data you can try to use the following. predictions = result.get_prediction(out_of_sample_df) predictions.summary_frame(alpha=0.05) I found the summary_frame() method buried here and you can find the get_prediction() method here. You can change the significance level of the confidence interval and prediction interval by modifying the “alpha” parameter. I am posting this here because this was … Read more

## Function to calculate R2 (R-squared) in R

You need a little statistical knowledge to see this. R squared between two vectors is just the square of their correlation. So you can define you function as: rsq <- function (x, y) cor(x, y) ^ 2 Sandipan’s answer will return you exactly the same result (see the following proof), but as it stands it … Read more

## Add error bars to show standard deviation on a plot in R

A solution with ggplot2 : qplot(x,y)+geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd), width=0.25)

Categories r

## How do I calculate r-squared using Python and Numpy?

A very late reply, but just in case someone needs a ready function for this: scipy.stats.linregress i.e. slope, intercept, r_value, p_value, std_err = scipy.stats.linregress(x, y) as in @Adam Marples’s answer.

## What do all the distributions available in scipy.stats look like?

Visualizing all scipy.stats distributions Based on the list of scipy.stats distributions, plotted below are the histograms and PDFs of each continuous random variable. The code used to generate each distribution is at the bottom. Note: The shape constants were taken from the examples on the scipy.stats distribution documentation pages. alpha(a=3.57, loc=0.00, scale=1.00) anglit(loc=0.00, scale=1.00) arcsine(loc=0.00, … Read more

## Rolling median algorithm in C

I have looked at R’s src/library/stats/src/Trunmed.c a few times as I wanted something similar too in a standalone C++ class / C subroutine. Note that this are actually two implementations in one, see src/library/stats/man/runmed.Rd (the source of the help file) which says \details{ Apart from the end values, the result \code{y = runmed(x, k)} simply … Read more