problem installing coxph function in R

hello,
I would be happy to get some help..
i am trying to install coxph function but receive the massage:
install.packages("coxph")
Installing package into ‘C:/Users/USER/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘coxph’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at

i have R version 4.2.3
????

The function coxph is provided by the package survival therefore, try to install and load the library survival

thank you,
i tried to install again survival but them i get:
cox <- coxph(Surv(age, gender))
Error in coxph.control(...) : could not find function "coxph.control"

cox <- coxph(Surv(age, gender, data = g))
Error in coxph.control(...) : could not find function "coxph.control"
cox <- coxph(Surv(fu_time, death) , data = g)
Error in coxph.control(...) : could not find function "coxph.control"
cox <- coxph(Surv(fu_time, death) ~ ethnicgroup, data = g)
Error in coxph.control(...) : could not find function "coxph.control"
install.packages("coxph.control")
Installing package into ‘C:/Users/USER/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘coxph.control’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at

thank you for the help

coxph.control is not a package, so you cant install it.
it is a function that should be present in an up to date version of 'survival'

what version do you have ?

packageVersion("survival")

I have 3.5.0

tahnks for the help,
i have survival version 3.5.3

now tried to download it as version 3.5.0 and still same result:
install.packages("survival", version='3.5.0')
Installing package into ‘C:/Users/USER/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/survival_3.5-5.zip'
Content type 'application/zip' length 6602925 bytes (6.3 MB)
downloaded 6.3 MB

package ‘survival’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\USER\AppData\Local\Temp\RtmpqwhrqZ\downloaded_packages

cox <- coxph(Surv(fu_time, death) ~ ethnicgroup, data = g)
Error in coxph.control(...) : could not find function "coxph.control"

are you remembering to load the library/package with either of

require(survival)

or

library(survival)

in general you can only access the functions of an installed package by first attaching them via require/library into your active session.

yes i tried but still doesnt work:

library(survival)

Attaching package: ‘survival’

The following object is masked by ‘.GlobalEnv’:

coxph

cox <- coxph(Surv(fu_time, death) ~ ethnicgroup, data = g)
Error in innerterms(formula[1:2]) : could not find function "innerterms"

I'm guessing you havent restarted your R session, since installing survival package again ?
restart your R clean, without restoring your workspace and try again

p.s. install.packages does not have a version command, so you installed the latest available version (which is not a bad thing) , but you seemed unaware of that, so I thought I'd point it out.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.