linear-regression

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

倾然丶 夕夏残阳落幕 提交于 2019-11-28 08:28:21
问题 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

How to return predicted values,residuals,R square from lm.fit in R?

自古美人都是妖i 提交于 2019-11-28 07:49:27
this piece of code will return coefficients :intercept , slop1 , slop2 set.seed(1) n=10 y=rnorm(n) x1=rnorm(n) x2=rnorm(n) lm.ft=function(y,x1,x2) return(lm(y~x1+x2)$coef) res=list(); for(i in 1:n){ x1.bar=x1-x1[i] x2.bar=x2-x2[i] res[[i]]=lm.ft(y,x1.bar,x2.bar) } If I type: > res[[1]] I get: (Intercept) x1 x2 -0.44803887 0.06398476 -0.62798646 How can we return predicted values,residuals,R square, ..etc? I need something general to extract whatever I need from the summary? There are a couple of things going on here. First, you are better off combining your variables into a data.frame: df <-

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

夙愿已清 提交于 2019-11-28 07:01:58
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . 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

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

拥有回忆 提交于 2019-11-28 03:56:28
问题 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

Linear regression analysis with string/categorical features (variables)?

ⅰ亾dé卋堺 提交于 2019-11-28 03:23:58
Regression algorithms seem to be working on features represented as numbers. For example: This dataset doesn't contain categorical features/variables. It's quite clear how to do regression on this data and predict price. But now I want to do regression analysis on data that contain categorical features: There are 5 features: District , Condition , Material , Security , Type How can I do regression on this data? Do I have to transform all this string/categorical data to numbers manually? I mean if I have to create some encoding rules and according to that rules transform all data to numeric

matrices are not aligned Error: Python SciPy fmin_bfgs

无人久伴 提交于 2019-11-28 02:42:40
问题 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

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

我的梦境 提交于 2019-11-28 02:08:38
问题 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? 回答1: 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

Loop linear regression and saving coefficients

放肆的年华 提交于 2019-11-28 00:31:01
This is part of the dataset (named "ME1") I'm using (all variables are numeric): Year AgeR rateM 1 1751 -1.0 0.241104596 2 1751 -0.9 0.036093609 3 1751 -0.8 0.011623734 4 1751 -0.7 0.006670552 5 1751 -0.6 0.006610552 6 1751 -0.5 0.008510828 7 1751 -0.4 0.009344041 8 1751 -0.3 0.011729740 9 1751 -0.2 0.010988005 10 1751 -0.1 0.015896107 11 1751 0.0 0.018190140 12 1751 0.1 0.024588340 13 1751 0.2 0.029801362 14 1751 0.3 0.044515912 15 1751 0.4 0.055240354 16 1751 0.5 0.088476758 17 1751 0.6 0.119045309 18 1751 0.7 0.167866571 19 1751 0.8 0.239244825 20 1751 0.9 0.329683010 21 1751 1.0 0

lm function in R does not give coefficients for all factor levels in categorical data

若如初见. 提交于 2019-11-28 00:01:02
I was trying out linear regression with R using categorical attributes and observe that I don't get a coefficient value for each of the different factor levels I have. Please see my code below, I have 5 factor levels for states, but see only 4 values of co-efficients. > states = c("WA","TE","GE","LA","SF") > population = c(0.5,0.2,0.6,0.7,0.9) > df = data.frame(states,population) > df states population 1 WA 0.5 2 TE 0.2 3 GE 0.6 4 LA 0.7 5 SF 0.9 > states=NULL > population=NULL > lm(formula=population~states,data=df) Call: lm(formula = population ~ states, data = df) Coefficients: (Intercept)

R: lm() result differs when using `weights` argument and when using manually reweighted data

眉间皱痕 提交于 2019-11-27 20:57:29
In order to correct heteroskedasticity in error terms, I am running the following weighted least squares regression in R : #Call: #lm(formula = a ~ q + q2 + b + c, data = mydata, weights = weighting) #Weighted Residuals: # Min 1Q Median 3Q Max #-1.83779 -0.33226 0.02011 0.25135 1.48516 #Coefficients: # Estimate Std. Error t value Pr(>|t|) #(Intercept) -3.939440 0.609991 -6.458 1.62e-09 *** #q 0.175019 0.070101 2.497 0.013696 * #q2 0.048790 0.005613 8.693 8.49e-15 *** #b 0.473891 0.134918 3.512 0.000598 *** #c 0.119551 0.125430 0.953 0.342167 #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0