sdllc / Basic-Excel-R-Toolkit

http://bert-toolkit.com
205 stars 42 forks source link

BERT does not support function arguments (e.g. Y ~ X ). #42

Open DukeTogoGolgo13 opened 7 years ago

DukeTogoGolgo13 commented 7 years ago

I am trying to run glms models from data in Excel. How can I do this when BERT does not support functional arguments. The documentation seems to mention a work around but its quite general and I can't seem to make sense of it. Is it possible to show a working example where you are able to run a GLM model (or LM model for that matter) via BERT? Thanks in advance.

duncanwerner commented 7 years ago

Basically the only values that can go into a single Excel cell are single scalars (you can have multiple values if you enter the function as an array). But you can't pass functions around because Excel has no concept of these. So if you want to use function arguments, you have to do that on the R side.

Here's a function that fits a polynomial:

fit.poly <- function( x, y, degree ){
    x <- unlist(as.numeric(x));
    y <- unlist(as.numeric(y));
    model <- lm( y ~ poly(x, degree=degree, raw=T ));
    matrix( model$coefficients, nrow=1 ); 
}
DukeTogoGolgo13 commented 7 years ago

That worked. Many thanks!!!

The key for me was the piece of code matrix( model$coefficients, nrow=1 );

Kind Regards,