polynomials

How to add all variables its second degree in lm()? [duplicate]

柔情痞子 提交于 2019-12-04 06:04:24
问题 This question already has an answer here : R:fit dynamic number of explanatory variable into polynomial regression (1 answer) Closed 3 years ago . I have a dataframe with 16 variables. When I do multiple linear regression I do the following: fit <- lm(y ~ .,data=data) Now, I know how to add a second degree term of one of the variables: fit2 <- lm(y ~ poly(x1,2) + .,data=data) But now I don't want to write this out for all of my 16 variables. How can I do this in an easy way for all my

How to analyse a sparse adjacency matrix?

﹥>﹥吖頭↗ 提交于 2019-12-04 05:42:45
I am researching sparse adjacency matrices where most cells are zeros and some ones here-and-there, each relationship between two cells has a polynomial description that can be very long and their analysis manually time-consuming. My instructor is suggesting purely algebraic method in terms of Gröbner bases but before proceeding I would like to know from purely computer science and programming perspective about how to analyse sparse adjacency matrices? Does there exist some data mining tools to analyse them? hhh Multivariate polynomial computation and Gröbner basis is an active research area.

How to model polynomial regression in R?

梦想的初衷 提交于 2019-12-04 01:42:58
问题 I've a dataset with 70 variables, and I want to try polynomial regression on it. If the number of columns were three/four I could just hand code something like this -- model <- lm(y ~ poly(var1,3) + poly(var2,3) + poly(var4,4) How would we go about this, if we have 70 variables? Should we type in manually names of all the variables or is there a easier method? 回答1: You could paste the formula, if all variables are named systematically: form <- as.formula(paste("y~", paste0("poly(var", 1:10, "

How to add all variables its second degree in lm()? [duplicate]

帅比萌擦擦* 提交于 2019-12-02 13:51:11
This question already has an answer here: R:fit dynamic number of explanatory variable into polynomial regression 1 answer I have a dataframe with 16 variables. When I do multiple linear regression I do the following: fit <- lm(y ~ .,data=data) Now, I know how to add a second degree term of one of the variables: fit2 <- lm(y ~ poly(x1,2) + .,data=data) But now I don't want to write this out for all of my 16 variables. How can I do this in an easy way for all my variables? When assuming the first variable in data is our 'y', we get this: as.formula( paste('y ~',paste('poly(',colnames(data[-1]),

Sort polynomials Common Lisp

a 夏天 提交于 2019-12-02 05:11:21
问题 I'm trying to sort a list of polynomials written in this format: (M [coefficient] [total degree] [Variable List]). example: ((M 1 1 ((V 1 A))) (M 1 2 ((V 1 A) (V 1 C))) (M 1 2 ((V 2 A))) (M 1 2 ((V 1 A) (V 1 B)))) This is: a + a * c + a ^ 2 + a * b, I need to get a + a * b + c + a * a ^ 2, because a * b < a ^ 2 and a < a ^ 2. I tried to use the function sort, but my output is: ((M 1 1 ((V 1 A))) (M 1 2 ((V 2 A))) (M 1 2 ((V 1 A) (V 1 B))) (M 1 2 ((V 1 A) (V 1 C)))) that is a + a ^ 2 + a * b +

Laguerre polynomials in MATLAB

纵饮孤独 提交于 2019-12-02 03:46:23
I tried using the .. command in MATLAB to generate Laguerre polynomials but I keep getting this error every time: I found this in the help section: Since I have defined x as symbolic I shouldn't be getting this error. Also on website I found this which says that the function does not run in MATLAB. Can anyone help? Thanks in advance Like you say, and the matlab help says this function only works inside mupad, maybe in later versions it works in matlab console. If you want to use it, write mupad in Matlab Command window and then use it in the mupad, matlab will return you the result as I show

Sort polynomials Common Lisp

空扰寡人 提交于 2019-12-02 02:27:30
I'm trying to sort a list of polynomials written in this format: (M [coefficient] [total degree] [Variable List]). example: ((M 1 1 ((V 1 A))) (M 1 2 ((V 1 A) (V 1 C))) (M 1 2 ((V 2 A))) (M 1 2 ((V 1 A) (V 1 B)))) This is: a + a * c + a ^ 2 + a * b, I need to get a + a * b + c + a * a ^ 2, because a * b < a ^ 2 and a < a ^ 2. I tried to use the function sort, but my output is: ((M 1 1 ((V 1 A))) (M 1 2 ((V 2 A))) (M 1 2 ((V 1 A) (V 1 B))) (M 1 2 ((V 1 A) (V 1 C)))) that is a + a ^ 2 + a * b + a * c. I use: (defun sort-poly (a b) (cond (t (sort-poly-helper (varpowers a) (varpowers b))))) (defun

Why predicted polynomial changes drastically when only the resolution of prediction grid changes?

ε祈祈猫儿з 提交于 2019-12-02 00:28:06
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 3 years ago . Why I have the exact same model, but run predictions on different grid size (by 0.001 vs by 0.01) getting different predictions? set.seed(0) n_data=2000 x=runif(n_data)-0.5 y=0.1*sin(x*30)/x+runif(n_data) plot(x,y) poly_df=5 x_exp=as.data.frame(cbind(y,poly(x, poly_df))) fit=lm(y~.,data=x_exp) x_plt1=seq(-1,1,0.001) x_plt_exp1=as.data.frame(poly(x_plt1,poly_df)) lines(x_plt1

Why predicted polynomial changes drastically when only the resolution of prediction grid changes?

 ̄綄美尐妖づ 提交于 2019-12-01 22:24:45
Why I have the exact same model, but run predictions on different grid size (by 0.001 vs by 0.01) getting different predictions? set.seed(0) n_data=2000 x=runif(n_data)-0.5 y=0.1*sin(x*30)/x+runif(n_data) plot(x,y) poly_df=5 x_exp=as.data.frame(cbind(y,poly(x, poly_df))) fit=lm(y~.,data=x_exp) x_plt1=seq(-1,1,0.001) x_plt_exp1=as.data.frame(poly(x_plt1,poly_df)) lines(x_plt1,predict(fit,x_plt_exp1),lwd=3,col=2) x_plt2=seq(-1,1,0.01) x_plt_exp2=as.data.frame(poly(x_plt2,poly_df)) lines(x_plt2,predict(fit,x_plt_exp2),lwd=3,col=3) 李哲源 This is a coding / programming problem as on my quick run I

How to model polynomial regression in R?

£可爱£侵袭症+ 提交于 2019-12-01 08:45:21
I've a dataset with 70 variables, and I want to try polynomial regression on it. If the number of columns were three/four I could just hand code something like this -- model <- lm(y ~ poly(var1,3) + poly(var2,3) + poly(var4,4) How would we go about this, if we have 70 variables? Should we type in manually names of all the variables or is there a easier method? You could paste the formula, if all variables are named systematically: form <- as.formula(paste("y~", paste0("poly(var", 1:10, ")", collapse="+"))) or (for polynomial of 3rd degree): form <- as.formula(paste("y~", paste0("poly(var", 1