Confidence ellipse formula in JS or R - r

What I have: A scatter chart(plot) of PCA. Plotted in JS. I have Rtools that Ive used to push PCA data to the client side.
What I'm trying to do: Plot a confidence ellipse formula.
I can't seem to find a straight forward formula for the CI ellipse. I came across a lot of theory and a lot of examples in R which give you the end result - an ellipse (One can use ggplot or CRAN to plot it).
But Im looking for a formula that I could use in the client side to plug my scatter chart points and calculate the ellipse or even better a function in R that would give me a formula for the ellipse.
I have the covariance matrix and Eigen vectors as well (calculated in R).
All suggestions much appreciated.

Haven't found a formula but after using Momocs:::conf_ell library I managed to get the vertices and the x,y points of an ellipse.
I will update this answer once I find the second part to my answer - a straight forward formula.

Related

Gaussian deconvolution of a density curve

I have a vector which I have made a density function for. It is a curve with multiple peaks, and I want to perform a Gaussian deconvolution in order to represent my density curve with multiple Gaussian curves. I am hoping there is a package that will allow me to do this, but I haven't found anything that has worked for me so far. I tried to follow the example given here (https://www.r-bloggers.com/fitting-mixture-distributions-with-the-r-package-mixtools/) but the vector I am working with is ~400 mb and won't play nicely with the mixtools package tools. I need something that will work with the size of the datasets I am working with or be able to work with the density curve directly. Any help appreciated, thank you!
I do not have sample data but I am happy to have it explained with the faithful dataset in R, I know I can find the density of faithful$waiting with density(faithful$waiting) and it plots just fine, but the deconvolution has me stuck.

R prcomp PCA rotation incorrectly mirroring data

Has anyone had any issue with R's prcomp PCA rotation function rotating THEN MIRRORING the data? When I use principle from the psych package, the rotation is correct. Also, when I do it manually with cosine angle, it is correct. But when I do prcomp, it mirrors the data after rotating it. prcomp has some nice visualizations that I want to use that principle does not have.
Correct rotation:
principal(PCADataFrame, nfactors=2, rotate="varimax")
Incorrect (mirrored) rotation)
prcomp(PCADataFrame, scale = TRUE)
I want to use
fviz_pca_biplot(res.pca)
to plot factor loadings, but this only works with prcomp. So if anyone knows of similar visualizations with principle, that would be helpful to.

How to reproduce this graphical explanation (a scatter plot) of how covariance works?

I found this graphical intuitive explanation of covariance:
32 binormal points drawn from distributions with the given covariances, ordered from most negative (bluest) to most positive (reddest)
The whole material can be found at:
https://stats.stackexchange.com/questions/18058/how-would-you-explain-covariance-to-someone-who-understands-only-the-mean
I would like to recreate this sort of graphical illustration in R, but I'm not sufficiently familiar with R's plotting tools. I don't even know where to start in order to get those colored rectangles between each pair of data points, let alone make them semi-transparent.
I think this could make a very efficient teaching tool.
The cor.rect.plot function in the TeachingDemos package makes plots similar to what is shown. You can modify the code for the function to make the plot even more similar if you desire.

Regression i Maple - finding the best possible curve

Given some data points plotted in a graph by:
plot(<<a>|<b>>,style=point);
How do I do regression through the points? That is finding the best possible curve, straight line etc.
You could look at the help-pages for the CurveFitting package, or those of Statistics,Regression. (Note that the latter of those should appear by entering regression in the Maple 16 Help browser's search box.)
a:=<1,2,3,4,5>:
b:=<2,5,10,17,26>:
P1:=plot(<a|b>,style=point,color=red):
C1:=Statistics:-Fit(s+t*x,a,b,x);
C2:=Statistics:-Fit(s+t*x+u*x^2,a,b,x);
plots:-display(
P1,
plot(C1, x=min(a)..max(a), color=green),
plot(C2, x=min(a)..max(a), color=blue)
);

Measuring the limit of a point on a smooth.spline in R

I'm not sure if that's the right terminology.
I've entered some data into R, and I've put a smooth.spline through it using the following command.
smoothingSpline = smooth.spline(year, rate, spar=0.35)
plot(x,y)
lines(smoothingSpline)
Now I'd like to measure some limits (or where the curve is at a given x point), and maybe do some predictive analysis on points that extend beyond the graph.
Are there commands in R for measuring (or predicting) the points along a curve?
Is ?predict.smooth.spline what you are looking for?

Resources