linear-regression

How to use aryule() in Matlab to extend a number series?

若如初见. 提交于 2019-12-25 04:36:34
问题 I have a series of numbers. I calculated the "auto-regression" between them using Yule-Walker method . But now how do I extend the series? Whole working is as follows: a) the series I use: 143.85 141.95 141.45 142.30 140.60 140.00 138.40 137.10 138.90 139.85 138.75 139.85 141.30 139.45 140.15 140.80 142.50 143.00 142.35 143.00 142.55 140.50 141.25 140.55 141.45 142.05 b) this data is loaded in to data using: data = load('c:\\input.txt', '-ascii'); c) the calculation of the coefficients: ar

Display all comparisons for factor variables in R for lm or coxph

拟墨画扇 提交于 2019-12-25 03:45:22
问题 In R, the default method when using a factor variable in regression is to use contrasts. I.E we set a reference class, and then the results are reported as (factor) vs. reference. For example, if we had 3 groups, and set 1 to be the reference group, then the results will be (2 vs 1) and (3 vs 1). But we don't get to see 3 vs 2. I know that you can get this by rerunning the regression and re-leveling with 2 as the reference class. But is there any way to get all comparisons in one line of code

Display all comparisons for factor variables in R for lm or coxph

混江龙づ霸主 提交于 2019-12-25 03:45:18
问题 In R, the default method when using a factor variable in regression is to use contrasts. I.E we set a reference class, and then the results are reported as (factor) vs. reference. For example, if we had 3 groups, and set 1 to be the reference group, then the results will be (2 vs 1) and (3 vs 1). But we don't get to see 3 vs 2. I know that you can get this by rerunning the regression and re-leveling with 2 as the reference class. But is there any way to get all comparisons in one line of code

How to find the maximum value of a function changing one constant value in R?

 ̄綄美尐妖づ 提交于 2019-12-24 21:42:26
问题 I have the following linearized plot: a and b are vectors with data, c is a constant. The task is find a value of c that maximizes R^2 for a linear regression a <- c(56.60, 37.56, 15.80, 27.65, 9.20, 5.05, 3.54) b <- c(23.18, 13.49, 10.45, 7.24, 5.44, 4.19, 3.38) c <- 1 x <- log(a) y <- log((c*(a/b))-1) rsq <- function(x, y) summary(lm(y~x))$r.squared rsq(x, y) optimise(rsq, maximum = TRUE) 回答1: This works: a <- c(56.60, 37.56, 15.80, 27.65, 9.20, 5.05, 3.54) b <- c(23.18, 13.49, 10.45, 7.24,

Linear fit with Math.NET: error in data and error in fit parameters?

孤街浪徒 提交于 2019-12-24 14:31:55
问题 I am trying to use Math.NET to perform a simple linear fit through a small set of datapoints. Using Fit.Line I am very easily able to perform the linear fit and obtain the slope and intercept: Tuple<double, double> result = Fit.Line(xdata, ydata); var intercept = result.Item1; var slope = result.Item2; This is very simple, but what about errors? Errors in y-data My y-data might contain error bars, can Math.NET take these errors into account? There are no errors in x-data, just in y-data.

implementation of linear regression, values of weights increases to Inf

帅比萌擦擦* 提交于 2019-12-24 11:30:03
问题 I am implementing a program that performs linear regression on the following dataset: http://www.rossmanchance.com/iscam2/data/housing.txt My program is as follows: import numpy as np import pandas as pd import matplotlib.pyplot as plt def abline(X,theta,Y): yValues=calcH(X,theta) plt.xlim(0, 5000) plt.ylim(0, 2000000) plt.xlabel("sqft") plt.ylabel("price") plt.gca().set_aspect(0.001, adjustable='box') plt.plot(X,Y,'.',X, yValues, '-') plt.show() def openFile(fileR): f=pd.read_csv(fileR,sep="

Linear regression with `lm()`: prediction interval for aggregated predicted values

故事扮演 提交于 2019-12-24 10:47:21
问题 I'm using predict.lm(fit, newdata=newdata, interval="prediction") to get predictions and their prediction intervals (PI) for new observations. Now I would like to aggregate (sum and mean) these predictions and their PI's based on an additional variable (i.e. a spatial aggregation on the zip code level of predictions for single households). I learned from StackExchange, that you cannot aggregate the prediction intervals of single predictions just by aggregating the limits of the prediction

matplotlib plot_surface for 2-dimensional multiple linear regression

▼魔方 西西 提交于 2019-12-24 07:59:23
问题 I have many points of data with three dimensions: x1, x2, and y. I'm able to calculate the multiple linear regression of these points, and I'm able to display the points on a 3D scatter plot, but I don't know how to plot the multiple linear regression I calculated for those points: the same way you can plot a line of best fit in a 1D linear regression, I'm interested in plotting a "plane of best fit" for a 2D linear regression. My code follows: import numpy as np from mpl_toolkits.mplot3d

Linear interpolation of data

时光总嘲笑我的痴心妄想 提交于 2019-12-24 07:17:29
问题 I have a data frame with the year (x) and an associated percentage (y) data.frame(x = c(1997,2000,2003,2006,2009,2010,2013,2014), y = c(.02,.023,.025,.024,.026,.027,.029,.031) Here is a line chart of this data frame : I would like to interpolate my data to get the percentage of missing years based on a linear regression. I could make a linear model of each piece of curve but it would be tedious. Is there a simple way to do it with R? INPUT : df = data.frame( year=c(1997,2000,2003,2006,2009

How to compute the p-value in hypothesis testing (linear regression)

自闭症网瘾萝莉.ら 提交于 2019-12-24 07:13:03
问题 Currently I'm working on an awk script to do some statistical analysis on measurement data. I'm using linear regression to get parameter estimates, standard errors etc. and would also like to compute the p-value for a null-hypothesis test (t-test). This is my script so far, any idea how to compute the p-value? BEGIN { ybar = 0.0 xbar = 0.0 n = 0 a0 = 0.0 b0 = 0.0 qtinf0975 = 1.960 # 5% n = inf } { # y_i is in $1, x_i has to be counted n = n + 1 yi[n] = $1*1.0 xi[n] = n*1.0 } END { for ( i = 1