Displaying 20 results from an estimated 10000 matches similar to: "Trying to learn how to write an "advanced" function"
2023 Mar 16
3
Trying to learn how to write an "advanced" function
Although I owe thanks to Ramus and Ivan, I still do not know how to write and "advanced" function.
My most recent try (after looking at the material Ramus and Ivan set) still does not work. I am trying to run the lm function on two different formulae:
1) y~x,
2) y~x+z
Any corrections would be appreciated!
Thank you,
John
doit <- function(x){
ds <- deparse(substitute(x))
2024 Nov 27
4
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
Check out the dplyr package, specifically the mutate function.
# Create new column based on existing column value
df <- df %>% mutate(FirstDay = if(ID = 2, 5))
df
Repeat as needed to capture all of the day/firstday combinations you want to account for.
Like everything else in R, there are probably at least a dozen other ways to do this, between base R and all of the library packages
2017 Oct 23
2
Syntax for fit.contrast (from package gmodels)
David,
Again you have my thanks!.
You are correct. What I want is not technically a contrast. What I want is the estimate for "regional" and its SE. I don't mind if I get these on the log scale; I can get the anti-log. Can you suggest how I can get the point estimate and its SE for "regional"? The predict function will give the point estimate, but not (to my knowledge)
2018 Mar 21
3
Mean of a row of a data frame
I am trying to get the mean of a row of a data frame. My code follows:
roop <- data.frame(x=c(1,2,3),y=c(4,5,2),z=c(0,9,4))
roop
mean(roop[1,])
mean(roop[1,c("x","y","z")])
I get the following output:
> roop
x y z
1 1 4 0
2 2 5 9
3 3 2 4
> mean(roop[1,])
[1] NA
Warning message:
In mean.default(roop[1, ]) :
argument is not numeric or logical:
2017 Oct 23
1
Syntax for fit.contrast (from package gmodels)
David,
predict.glm and se.fit were exactly what I was looking for.
Many thanks!
John
John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax)
2017 Oct 22
3
Syntax for fit.contrast (from package gmodels)
David,
Thank you for responding to my post.
Please consider the following output (typeregional is a factor having two levels, "regional" vs. "general"):
Call:
glm(formula = events ~ type, family = poisson(link = log), data = data,
offset = log(SS))
Deviance Residuals:
Min 1Q Median 3Q Max
-43.606 -17.295 -4.651 4.204 38.421
Coefficients:
2024 Dec 01
6
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
Dear R help folks,
First my apologizes for sending several related questions to the list server. I am trying to learn how to manipulate data in R . . . and am having difficulty getting my program to work. I greatly appreciate the help and support list member give!
I am trying to write a program that will run through a data frame organized by ID and for the first line of each new group of data
2017 Oct 23
0
Syntax for fit.contrast (from package gmodels)
> On Oct 22, 2017, at 5:01 PM, Sorkin, John <jsorkin at som.umaryland.edu> wrote:
>
> David,
> Again you have my thanks!.
> You are correct. What I want is not technically a contrast. What I want is the estimate for "regional" and its SE.
There needs to be a reference value for the contrast. Contrasts are differences. I gave you the choice of two references
2006 May 12
4
Title of page with multiple plots
I want to place four plots on a page, and I would like to have all four
plots share a common title. I have tried the following code, but the
title is centered over the fourth graph and not centered across all four
plots. Does anyone have any suggestions?
R 2.1.1
windows xp
oldpar<-par(mfcol =c(1,4),ask=TRUE)
plot(p,varp)
plot(p,SEp)
plot(p,CVp)
plot(p,ppval)
title(paste("P and 95%CI
2023 Apr 07
2
R does not run under latest RStudio
I have also had difficulty running R in RStudio. Has anyone else had problems?
It will be a shame if we need to abandon R Studio. It is a very good IDE.
John
John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene
2005 Jul 28
4
CSV file and date. Dates are read as factors!
I am using read.csv to read a CSV file (produced by saving an Excel file
as a CSV file). The columns containing dates are being read as factors.
Because of this, I can not compute follow-up time, i.e.
Followup<-postDate-preDate. I would appreciate any suggestion that would
help me read the dates as dates and thus allow me to calculate follow-up
time.
Thanks
John
John Sorkin M.D., Ph.D.
Chief,
2024 Dec 11
1
SQL and R
And to answer the dependency question.
Neither is dependent on the other. But both can be complimentary.
If you consider that SQL*may* be a route to accessing your data (if it's in
a database).
And R *may* be a route to analysis of the data.
If the data is in a CSV file, Excel file, API etc. you don't need SQL. IF
it is in a database, you might extract it to CSV etc. or you might
2005 Jul 29
6
Binary outcome with non-absorbing outcome state
I am trying to model data in which subjects are followed through time to
determine if they fall, or do not fall. Some of the subjects fall once,
some fall several times. Follow-up time varies from subject to subject.
I know how to model time to the first fall (e.g. Cox Proportional
Hazards, Kaplan-Meir analyses, etc.) but I am not sure how I can model
the data if I include the data for those
2010 Dec 28
4
Reading sas7bdat files into R
Hi All,
I am trying to import a .sas7bdat file into R.
I tried using Hmisc package's sasxport.get() function.
temp <- sasxport.get("path\abcd.sas7bdat")
I get an error that says "Error in lookup.xport(file) : file not in SAS transfer format"
I am not familiar with SAS transfer format.
Could somebody please clarify what is it that I am missing,
Thanks for your
2011 Mar 19
3
Generating repeated measures data
How would one generate data to be used in a simulation of a repeated measures ANOVA given a known (1) within-person correlation with known (2) mean and SD of data obtained at each of three times of observation?
Thanks,
John
John Sorkin
Chief Biostatistics and Informatics
Univ. of Maryland School of Medicine
Division of Gerontology and Geriatric Medicine
JSorkin at grecc.umaryland.edu
2016 Apr 07
0
using apply to a data frame
??I would like to apply a function, fract, to the columns of a
dataframe. I tried the following
apply(data5NonEventEpochs,2,fract)
but, no surprise it did not work as apply works on matrices not data
frames. How can I apply a fuction to the columns of a data frame? (I
can't covert data5NonEventsEpochs to a matrix as it contains character
data).
Thank you,
John
John David Sorkin M.D., Ph.D.
2005 Oct 11
2
Two factor (or more) non-parametric comparison of means
Can anyone suggest a good non-parametric test, and an R implementation of the test, that allows for two or more factors? Wilcoxon signed rank allows for only one.
Thanks,
John
John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC and
University of Maryland School of Medicine Claude Pepper OAIC
University of Maryland School of Medicine
Division of
2007 Jan 18
3
selecting rows for inclusion in lm
I am having trouble selecting rows of a dataframe that will be included
in a regression. I am trying to select those rows for which the variable
Meno equals PRE. I have used the code below:
difffitPre<-lm(data[,"diff"]~data[,"Age"]+data[,"Race"],data=data[data[,"Meno"]=="PRE",])
summary(difffitPre)
The output from the summary indicates that
2007 Oct 01
4
data structure with coefficients, and call from lm()
Widows XP
R 2.3.1
I have been trying to make a data structure that will contain both the coefficients from a linear regression along with column and row titles AND the call, i.e.
myreg<-lm(y~x+y+z)
whatIwant<-cbind(c(summary(myreg)$call,"",""),summary(myreg)$coefficients)
Neither the statement above, nor any one of twenty variations I have tried work. I would appreciate
2020 Oct 06
4
Solving a simple linear equation using uniroot give error object 'x' not found
Colleagues,
I am trying to learn to use uniroot to solve a simple linear equation. I define the function, prove the function and a call to the function works. When I try to use uniroot to solve the equation I get an error message,
Error in yfu n(x,10,20) : object 'x' not found.
I hope someone can tell we how I can fix the problem