You may have additional scoping problems depending on where you various
variables exist, but your Trend function syntax is incorrect. You need
parentheses around your arguments to the lm call, and you left out the '~' in
your formula. In addition, don't fool yourself by your use of the names CO2
and logTrop_Aerosol as the function arguments. Those arguments don't refer to
variables in the global environment. Function parameters have local scope in
the function.
Trend <- function(x,CO2,logTrop_Aerosol) { lm(x ~ CO2 + logTrop_Aerosol)}
Dan
Daniel Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services
-----Original Message-----
From: R-help [mailto:[email protected]] On Behalf Of Matthias Worni
Sent: Thursday, November 12, 2015 8:28 AM
To: [email protected]
Subject: [R] Compute Regressions with R-Function
Hello
I was trying to set up a function() that allows easely to calculate regressions
for severel dependent variables with the same independent variables.
My function looked like this but was turned down by an error (Im quiet new to R
Studio). So here is my solution:
b
CO2
logTrop_Aerosol
lm(b ~ CO2 + logTrop_Aerosol )
Trend <- function(x,CO2,logTrop_Aerosol) { lm x CO2 + logTrop_Aerosol}
b is a vector containing 400 values of heat content
CO2 also contains 400 values as well as logTropAerosol
my idea would be that I simply can replace x (heat content) by other vectors
containing heat content.
The error I got was the following:
Error: unexpected symbol in "Trend <- function(x,y,z) { lm x"
Thanks a lot for the help!
Best Matthias
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.