least-squares

Difference in Differences in Python + Pandas

ぃ、小莉子 提交于 2019-12-04 13:44:24
问题 I'm trying to perform a Difference in Differences (with panel data and fixed effects) analysis using Python and Pandas. I have no background in Economics and I'm just trying to filter the data and run the method that I was told to. However, as far as I could learn, I understood that the basic diff-in-diffs model looks like this: I.e., I am dealing with a multivariable model. Here it follows a simple example in R: https://thetarzan.wordpress.com/2011/06/20/differences-in-differences-estimation

Fitting an ellipsoid to 3D data points

十年热恋 提交于 2019-12-04 11:56:13
问题 I have a large set of 3D data points to which I want to fit to an ellipsoid. My maths is pretty poor, so I'm having trouble implementing the least squares method without any math libraries. Does anyone know of or have a piece of code that can fit an ellipsoid to data which I can plug straight into my project? In C would be best, but it should be no problem for me to convert from C++, Java, C#, python etc. EDIT: Just being able to find the centre would be a huge help too. Note that the points

Solving normal equation gives different coefficients from using `lm`?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 05:01:44
问题 I wanted to compute a simple regression using the lm and plain matrix algebra. However, my regression coefficients obtained from matrix algebra are only half of those obtained from using the lm and I have no clue why. Here's the code boot_example <- data.frame( x1 = c(1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L), x2 = c(0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L), x3 = c(1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L), x4 = c(0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L), x5 = c(1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L), x6 = c(0L, 1L,

C# Algebra Linear Library

一曲冷凌霜 提交于 2019-12-04 03:56:24
问题 I'm looking for a C# linear algebra library. I wan't to solve a homogeneous linear system with least squares minimization. I've been trying to use some librarys but I was just able to find the trivial solution. Any recommendations? 回答1: See: http://www.meta-numerics.net/ http://www.mathdotnet.com/ http://linearalgebra.codeplex.com/ They are open source too! 回答2: As commenter oleksii mentioned, you can use Accord.NET to achieve this as well. But you can also use its Solver extension method for

Fit points to a plane algorithms, how to iterpret results?

你说的曾经没有我的故事 提交于 2019-12-03 19:28:48
问题 Update : I have modified the Optimize and Eigen and Solve methods to reflect changes. All now return the "same" vector allowing for machine precision. I am still stumped on the Eigen method. Specifically How/Why I select slice of the eigenvector does not make sense. It was just trial and error till the normal matched the other solutions. If anyone can correct/explain what I really should do, or why what I have done works I would appreciate it. . Thanks Alexander Kramer, for explaining why I

get the R^2 value from scipy.linalg.lstsq

余生长醉 提交于 2019-12-03 17:12:58
I have a fitted 3D data-set using scipy.linalg.lstsq function. I was using: # best-fit quadratic curve A = np.c_[np.ones(data.shape[0]), data[:,:2], np.prod(data[:,:2], axis=1), data[:,:2]**2] C,_,_,_ = scipy.linalg.lstsq(A, data[:,2]) #evaluating on grid Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX*YY, XX**2, YY**2], C).reshape(X.shape) But How can I be able to get the R^2 value from this for the fitted-surface .? Is there any way I can check the significance of the fitting result ? Any ideas related to that would be highly appreciated. thank you. etna Following http://en.wikipedia.org/wiki

pseudo inverse of sparse matrix in python

荒凉一梦 提交于 2019-12-03 14:39:38
I am working with data from neuroimaging and because of the large amount of data, I would like to use sparse matrices for my code (scipy.sparse.lil_matrix or csr_matrix). In particular, I will need to compute the pseudo-inverse of my matrix to solve a least-square problem. I have found the method sparse.lsqr, but it is not very efficient. Is there a method to compute the pseudo-inverse of Moore-Penrose (correspondent to pinv for normal matrices). The size of my matrix A is about 600'000x2000 and in every row of the matrix I'll have from 0 up to 4 non zero values. The matrix A size is given by

How to use leastsq function from scipy.optimize in python to fit both a straight line and a quadratic line to data sets x and y

随声附和 提交于 2019-12-03 11:59:28
How would i fit a straight line and a quadratic to the data set below using the leastsq function from scipy.optimize? I know how to use polyfit to do it. But i need to use leastsq function. Here are the x and y data sets: x: 1.0,2.5,3.5,4.0,1.1,1.8,2.2,3.7 y: 6.008,15.722,27.130,33.772,5.257,9.549,11.098,28.828 Can someone help me out please? The leastsq() method finds the set of parameters that minimize the error function ( difference between yExperimental and yFit). I used a tuple to pass the parameters and lambda functions for the linear and quadratic fits. leastsq starts from a first guess

Difference in Differences in Python + Pandas

馋奶兔 提交于 2019-12-03 07:32:57
I'm trying to perform a Difference in Differences (with panel data and fixed effects) analysis using Python and Pandas. I have no background in Economics and I'm just trying to filter the data and run the method that I was told to. However, as far as I could learn, I understood that the basic diff-in-diffs model looks like this: I.e., I am dealing with a multivariable model. Here it follows a simple example in R: https://thetarzan.wordpress.com/2011/06/20/differences-in-differences-estimation-in-r-and-stata/ As it can be seen, the regression takes as input one dependent variable and tree sets

trying to display original and fitted data (nls + dnorm) with ggplot2's geom_smooth()

孤街醉人 提交于 2019-12-03 05:13:31
问题 I am exploring some data, so the first thing I wanted to do was try to fit a normal (Gaussian) distribution to it. This is my first time trying this in R, so I'm taking it one step at a time. First I pre-binned my data: myhist = data.frame(size = 10:27, counts = c(1L, 3L, 5L, 6L, 9L, 14L, 13L, 23L, 31L, 40L, 42L, 22L, 14L, 7L, 4L, 2L, 2L, 1L) ) qplot(x=size, y=counts, data=myhist) Since I want counts, I need to add a normalization factor (N) to scale up the density: fit = nls(counts ~ N *