linear-regression

Why does the number of rows change during AIC in R? How to ensure that this doesn't happen?

坚强是说给别人听的谎言 提交于 2019-12-30 09:22:28
问题 I'm trying to find a minimal adequate model using AIC in R. I keep getting the following error: Error in step(model) : number of rows in use has changed: remove missing values? My data: data<-structure(list(ID = c(1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 27L, 28L, 29L, 30L, 31L, 33L, 34L, 35L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,

Why does the number of rows change during AIC in R? How to ensure that this doesn't happen?

空扰寡人 提交于 2019-12-30 09:22:13
问题 I'm trying to find a minimal adequate model using AIC in R. I keep getting the following error: Error in step(model) : number of rows in use has changed: remove missing values? My data: data<-structure(list(ID = c(1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 27L, 28L, 29L, 30L, 31L, 33L, 34L, 35L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,

Moving window regression

笑着哭i 提交于 2019-12-30 07:52:29
问题 I want to perform a moving window regression on every pixel of two raster stacks representing Band3 and Band4 of Landsat data. The result should be two additional stacks, one representing the Intercept and the other one representing the slope of the regression. So layer 1 of stack "B3" and stack "B4" result in layer 1 of stack "intercept" and stack "slope". Layer 2 of stack B3 and stack B4 result in layer 2,.... and so on. I already came along the gwr function, but want to stay in the raster

Machine learning - Linear regression using batch gradient descent

大兔子大兔子 提交于 2019-12-28 03:32:16
问题 I am trying to implement batch gradient descent on a data set with a single feature and multiple training examples ( m ). When I try using the normal equation, I get the right answer but the wrong one with this code below which performs batch gradient descent in MATLAB. function [theta] = gradientDescent(X, y, theta, alpha, iterations) m = length(y); delta=zeros(2,1); for iter =1:1:iterations for i=1:1:m delta(1,1)= delta(1,1)+( X(i,:)*theta - y(i,1)) ; delta(2,1)=delta(2,1)+ (( X(i,:)*theta

Linear Regression Returns Different Results Than Synthetic Parameters

主宰稳场 提交于 2019-12-25 18:24:40
问题 trying this code: from sklearn import linear_model import numpy as np x1 = np.arange(0,10,0.1) x2 = x1*10 y = 2*x1 + 3*x2 X = np.vstack((x1, x2)).transpose() reg_model = linear_model.LinearRegression() reg_model.fit(X,y) print reg_model.coef_ # should be [2,3] print reg_model.predict([5,6]) # should be 2*5 + 3*6 = 28 print reg_model.intercept_ # perfectly at the expected value of 0 print reg_model.score(X,y) # seems to be rather confident to be right The results are [ 0.31683168 3.16831683]

Customizing tables in Stata

青春壹個敷衍的年華 提交于 2019-12-25 14:49:57
问题 Using Stata14 on windows, I am wondering how to build customized tables from several regression results. Here is an example. We have reg y, x1 predict resid1, residuals summarize resid1 Which gives: Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- resid1 | 5,708,529 4.83e-11 .7039736 -3.057633 3.256382 And run another regrerssion and similarly obtain the residuals: reg y, x2 predict resid2, residuals I would like to create a table

Customizing tables in Stata

一笑奈何 提交于 2019-12-25 14:49:24
问题 Using Stata14 on windows, I am wondering how to build customized tables from several regression results. Here is an example. We have reg y, x1 predict resid1, residuals summarize resid1 Which gives: Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- resid1 | 5,708,529 4.83e-11 .7039736 -3.057633 3.256382 And run another regrerssion and similarly obtain the residuals: reg y, x2 predict resid2, residuals I would like to create a table

Calling R function within SQL - HANA database

喜夏-厌秋 提交于 2019-12-25 06:07:16
问题 When I call Linear Regression function of R on the data set I get an error message stating Could not execute 'CALL ANAGAPPAN.USE_LM("POWER_CONSUMPTION","POWER_CONSUMPTION_OUT") WITH OVERVIEW' in 280 ms 668 µs . SAP DBTech JDBC: [2048]: column store error: search table error: [34086] Convert data error: Convert Data from R to NewDB failed.;Column 'POWER_APP' not computed from R. Code is SELECT POWER_APP,POWER_DB,CPUTI,DBTI,DBSU,KBYTES_TRANSFERRED FROM "POWER_CONSUMPTION"; CREATE COLUMN TABLE

How to write interactions in regressions in R?

心不动则不痛 提交于 2019-12-25 05:00:20
问题 DF <- data.frame(factor1=rep(1:4,1000), factor2 = rep(1:4,each=1000),base = rnorm(4000,0,1),dep=rnorm(4000,400,5)) DF$f1_1 = DF$factor1 == 1 DF$f1_2 = DF$factor1 == 2 DF$f1_3 = DF$factor1 == 3 DF$f1_4 = DF$factor1 == 4 DF$f2_1 = DF$factor2 == 1 DF$f2_2 = DF$factor2 == 2 DF$f2_3 = DF$factor2 == 3 DF$f2_4 = DF$factor2 == 4 I want to run the following regression: Dep = (f1_1 + f1_2 + f1_3 + f1_4)*(f2_1 + f2_2 + f2_3 + f2_4)*(base+base^2+base^3+base^4+base^5) Is there a smarter way to do it? 回答1:

scope from add1()-command in R

可紊 提交于 2019-12-25 04:57:13
问题 I am not sure how to use the add1 command. Suppose I have a model y=b0+b1*x1 and I would like to know if it would be a better fit to add more independent variables. Now I would test all models y=b0+b1*x1+b2*x2 with different x2 (my different independent variables). The add1 command somehow needs a "scope". I am not sure of, what that is. I could not find out how to use the add1 command. If I do this: add1(fittedmodel) I get an error, so I suppose I need to specify which variable I want to use