regression on 2d vector in r

by Sevan Harootonian   Last Updated July 12, 2018 01:19 AM

Trying to do a simple regression on a 2d vectors. I don't think this is the right way.

vec1x= c(0.4191, -0.0064, -0.1071, 0.0605, -0.0290)

vec1y= c(8.0054, 5.7876, 6.9907, 7.9606, 8.8073)

vec2x= c(2.5424, 5.1469, 4.7073, 4.3420, 6.7717)

vec2y= c(1.1129, 2.6307, 1.7691, 0.3857, -1.6576)

vec3x= c(1.8899, 3.7936, 4.3746, 2.7874, 1.3930)

vec3y= c(9.6567, 7.4949, 6.7109, 6.9061, 8.7460)

REG=glm(c(vec3x,vec3y) ~ c(vec1x,vec1y)+ c(vec2x,vec2y))

but when I run the X and Y separately I get different beta (I should?).

Is there another type of regression I can use that can take care of this 2d? Im new to this stuff.

Answers 1

For simple linear regression, you should use the "lm" (which stands for linear models of which simple linear regression is one type) function rather than the "glm" (which stands for generalized linear models). The way to do this is to 1. Put all your Xs in a matrix and Ys in a vector 2. Combine the X and Y into a Data Frame (this is Rs default way or organizing statistical data. It seems weird and you could think of it as a matrix with some very descriptive labels) 3. run the lm function on the dataframe.

For examples see:

Anonymous Emu
Anonymous Emu
July 12, 2018 01:22 AM

Related Questions

Is parametric equivalent to linear?

Updated December 24, 2017 10:19 AM

Linear Model vs Log-Linear vs Negative Binomial

Updated June 09, 2017 02:19 AM

Path analysis vs linear model

Updated February 28, 2018 23:19 PM