Keith Christian
2024-Aug-22 19:07 UTC
[R] Linear regression and stand deviation at the Linux command line
R List, Please excuse this ultra-newbie post. I looked at this page but it's a bit beyond me. https://www2.kenyon.edu/Depts/Math/hartlaub/Math305%20Fall2011/R.htm I'm interested in R construct(s) to be entered at the command line that would output slope, y-intercept, and r-squared values read from a csv or other filename entered at the command line, and the same for standard deviation calculations, namely the standard deviation, variance, and z-scores for every data point in the file. E.g. $ ((R function for linear regression here)) slope, y-intercept, and r-squared, other related stats that R seems most capable of generating. linear_regression_data.csv file contents (Are line numbers, commas, etc. needed or no?) 1 20279 2 899 3 24747 4 12564 5 29543 $ ((R function for standard deviation here)) standard deviation, variance, z-scores, other related stats that R seems most capable of generating. standard_deviation_data.csv file contents (Are line numbers, commas, etc. needed or no?) 1 16837 2 9498 3 31389 4 2365 5 17384 Many thanks, ----------Keith
Sorkin, John
2024-Aug-22 20:53 UTC
[R] Linear regression and stand deviation at the Linux command line
Keith, I suggest you being by looking at a web page https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/lm It will introduce you to the lm function, the function that performs liner regression and the summary function which returns some of the material you are looking for. The page come complete with code that can be run via he web page. Once you review the web page, and hopefully try to run the analysis you want to run, you can again ask the R help list for additional help. There are other web pages that can help you, for example https://www.statology.org/logistic-regression-in-r/#:~:text=How%20to%20Perform%20Logistic%20Regression%20in%20R%20%28Step-by-Step%29,Predictions%20...%205%20Step%205%3A%20Model%20Diagnostics%20 Take the first steps, show that you are trying and the R help list will be very helpful. John John David Sorkin M.D., Ph.D. Professor of Medicine, University of Maryland School of Medicine; Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center Geriatrics Research, Education, and Clinical Center; PI Biostatistics and Informatics Core, University of Maryland School of Medicine Claude D. Pepper Older Americans Independence Center; Senior Statistician University of Maryland Center for Vascular Research; Division of Gerontology and Paliative Care, 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 Cell phone 443-418-5382 ________________________________________ From: R-help <r-help-bounces at r-project.org> on behalf of Keith Christian <keith1christian at gmail.com> Sent: Thursday, August 22, 2024 3:07 PM To: r-help at r-project.org Subject: [R] Linear regression and stand deviation at the Linux command line R List, Please excuse this ultra-newbie post. I looked at this page but it's a bit beyond me. https://www2.kenyon.edu/Depts/Math/hartlaub/Math305%20Fall2011/R.htm I'm interested in R construct(s) to be entered at the command line that would output slope, y-intercept, and r-squared values read from a csv or other filename entered at the command line, and the same for standard deviation calculations, namely the standard deviation, variance, and z-scores for every data point in the file. E.g. $ ((R function for linear regression here)) slope, y-intercept, and r-squared, other related stats that R seems most capable of generating. linear_regression_data.csv file contents (Are line numbers, commas, etc. needed or no?) 1 20279 2 899 3 24747 4 12564 5 29543 $ ((R function for standard deviation here)) standard deviation, variance, z-scores, other related stats that R seems most capable of generating. standard_deviation_data.csv file contents (Are line numbers, commas, etc. needed or no?) 1 16837 2 9498 3 31389 4 2365 5 17384 Many thanks, ----------Keith ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Ivan Krylov
2024-Aug-23 07:57 UTC
[R] Linear regression and stand deviation at the Linux command line
? Thu, 22 Aug 2024 13:07:37 -0600 Keith Christian <keith1christian at gmail.com> ?????:> I'm interested in R construct(s) to be entered at the command > line that would output slope, y-intercept, and r-squared values read > from a csv or other filename entered at the command line, and the same > for standard deviation calculations, namely the standard deviation, > variance, and z-scores for every data point in the file.If you'd like to script R at the command line, consider the commandArgs() function (try entering ?commandArgs at the R prompt). This way you can pass a file path to an R process without unsafely interpolating it into the R expression itself. These arguments can be given to R --args or to Rscript (without the --args). Also consider the 'littler' scripting-oriented R front-end <https://CRAN.R-project.org/package=littler>, which puts the command line arguments into the 'argv' variable and has a very convenient -d option which loads CSV data from the standard input into a variable named 'X'.> Are line numbers, commas, etc. needed or no?Depends on how you read it. By default, the function read.table() will expect your data to be separated by a mixture of tabs and spaces and will recognise a header if the first line contains one less column than the rest of the file. Enter ?read.table at the R prompt to see the available options (which include read.csv). Good introductions to R include, well, "An Introduction to R" [1] (also available by typing RShowDoc('R-intro') into the R prompt) and "Visual Statistics" by Dr. A. Shipunov [2]. Start with functions read.table(), lm(), scale(), sd(), summary(). Use str() to look at the structure of a variable: summary(lm(...)) will return a named list from which you can extract the values you are interested in (see ?summary.lm). When in doubt, call help(name_of_the_function). -- Best regards, Ivan [1] https://cran.r-project.org/doc/manuals/R-intro.html [2] http://web.archive.org/web/20230106210646/http://ashipunov.info/shipunov/school/biol_240/en/visual_statistics.pdf