linear-regression

Obtain standard errors of regression coefficients for an “mlm” object returned by `lm()`

萝らか妹 提交于 2019-11-29 14:50:12
I'd like to run 10 regressions against the same regressor, then pull all the standard errors without using a loop . depVars <- as.matrix(data[,1:10]) # multiple dependent variables regressor <- as.matrix([,11]) # independent variable allModels <- lm(depVars ~ regressor) # multiple, single variable regressions summary(allModels)[1] # Can "view" the standard error for 1st regression, but can't extract... allModels is stored as an "mlm" object, which is really tough to work with. It'd be great if I could store a list of lm objects or a matrix with statistics of interest. Again, the objective is

Is there a Java library for better linear regression? (E.g., iteratively reweighted least squares) [closed]

时光总嘲笑我的痴心妄想 提交于 2019-11-29 13:26:54
I am struggling to find a way to perform better linear regression. I have been using the Moore-Penrose pseudoinverse and QR decomposition with JAMA library , but the results are not satisfactory. Would ojAlgo be useful? I have been hitting accuracy limits that I know should not be there. The algorithm should be capable of reducing the impact of an input variable to zero. Perhaps this takes the form of iteratively reweighted least squares, but I do not know that algorithm and cannot find a library for it. The output should be a weight matrix or vector such that matrix multiplication of the

How to get a regression summary in Python scikit like R does?

浪尽此生 提交于 2019-11-29 11:19:40
问题 As an R user, I wanted to also get up to speed on scikit. Creating a linear regression model(s) is fine, but can't seem to find a reasonable way to get a standard summary of regression output. Code example: # Linear Regression import numpy as np from sklearn import datasets from sklearn.linear_model import LinearRegression # Load the diabetes datasets dataset = datasets.load_diabetes() # Fit a linear regression model to the data model = LinearRegression() model.fit(dataset.data, dataset

R linear regression issue : lm.fit(x, y, offset = offset, singular.ok = singular.ok, …)

北城余情 提交于 2019-11-29 10:44:35
I try a regression with R. I have the following code with no problem in importing the CSV file dat <- read.csv('http://pastebin.com/raw.php?i=EWsLjKNN',sep=";") dat # OK Works fine Regdata <- lm(Y~.,na.action=na.omit, data=dat) summary(Regdata) However when I try a regression it's not working. I get an error message: Erreur dans lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : aucun cas ne contient autre chose que des valeurs manquantes (NA) All my CSV file are numbers and if a "cell" is empty I have the "NA" value. Some column are not empty and some other row are sometimes

matrices are not aligned Error: Python SciPy fmin_bfgs

纵饮孤独 提交于 2019-11-29 09:20:48
Problem Synopsis: When attempting to use the scipy.optimize.fmin_bfgs minimization (optimization) function, the function throws a derphi0 = np.dot(gfk, pk) ValueError: matrices are not aligned error. According to my error checking this occurs at the very end of the first iteration through fmin_bfgs--just before any values are returned or any calls to callback. Configuration: Windows Vista Python 3.2.2 SciPy 0.10 IDE = Eclipse with PyDev Detailed Description: I am using the scipy.optimize.fmin_bfgs to minimize the cost of a simple logistic regression implementation (converting from Octave to

Get Confidence Interval For One Point On Regression Line In R?

泪湿孤枕 提交于 2019-11-29 08:35:34
How do I get the CI for one point on the regression line? I'm quite sure I should use confint() for that, but if I try this confint(model,param=value) it just gives me the same number as if I just type in confint(model) if I try without a value, it does not give me any values at all. What am I doing wrong? You want predict() instead of confint() . Also, as Joran noted, you'll need to be clear about whether you want the confidence interval or prediction interval for a given x. (A confidence interval expresses uncertainty about the expected value of y-values at a given x. A prediction interval

How to correctly `dput` a fitted linear model (by `lm`) to an ASCII file and recreate it later?

那年仲夏 提交于 2019-11-29 07:03:44
I want to persist a lm object to a file and reload it into another program. I know I can do this by writing/reading a binary file via saveRDS / readRDS , but I'd like to have an ASCII file instead of a binary file. At a more general level, I'd like to know why my idioms for reading in dput output in general is not behaving as I'd expect. Below are examples of making a simple fit, and successful and unsuccessful recreations of the model: dat_train <- data.frame(x=1:4, z=c(1, 2.1, 2.9, 4)) fit <- lm(z ~ x, dat_train) rm(dat_train) # Just to make sure fit is not dependent upon `dat_train

How to fit the 2D scatter data with a line with C++

╄→гoц情女王★ 提交于 2019-11-29 06:57:37
I used to work with MATLAB, and for the question I raised I can use p = polyfit(x,y,1) to estimate the best fit line for the scatter data in a plate. I was wondering which resources I can rely on to implement the line fitting algorithm with C++. I understand there are a lot of algorithms for this subject, and for me I expect the algorithm should be fast and meantime it can obtain the comparable accuracy of polyfit function in MATLAB. I would suggest coding it from scratch. It is a very simple implementation in C++. You can code up both the intercept and gradient for least-squares fit (the same

How to put a complicated equation into a R formula?

旧城冷巷雨未停 提交于 2019-11-29 04:03:48
We have the diameter of trees as the predictor and tree height as the dependent variable. A number of different equations exist for this kind of data and we try to model some of them and compare the results. However, we we can't figure out how to correctly put one equation into the corresponding R formula format. The trees data set in R can be used as an example. data(trees) df <- trees df$h <- df$Height * 0.3048 #transform to metric system df$dbh <- (trees$Girth * 0.3048) / pi #transform tree girth to diameter First, the example of an equation that seems to work well: form1 <- h ~ I(dbh ^ -1)

D3.js linear regression

假如想象 提交于 2019-11-29 03:43:52
问题 I searched for some help on building linear regression and found some examples here: nonlinear regression function and also some js libraries that should cover this, but unfortunately I wasn't able to make them work properly: simple-statistics.js and this one: regression.js With regression.js I was able to get the m and b values for the line, so I could use y = m*x + b to plot the line that followed the linear regression of my graph, but couldn't apply those values to the line generator, the