Fitting data to logistic function in R












0















I'm trying to fit world sales data for BEV and PHEV to a logistic growth function.



For an example, I'm using R-code for Logistic Growth Model of Australian Population in R (by Elise Gould)



But with this method I'm getting the error:




Error in qr.default(.swts * gr) :
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In Ops.factor(xmid, input) : ‘-’ not meaningful for factors




My data is:



EV_temp<-structure(list(Country = structure(c(21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L), .Label = c("Australia",
"Brazil", "Canada", "Chile", "China", "Finland", "France", "Germany",
"India", "Japan", "Korea", "Mexico", "Netherlands", "New Zealand",
"Norway", "Others", "Portugal", "South Africa", "Sweden", "Thailand",
"Total", "United Kingdom", "United States"), class = "factor"),
Year = structure(1:13, .Label = c("2005", "2006", "2007",
"2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015",
"2016", "2017"), class = "factor"), TotalSales = c(1.89,
2.23, 2.69, 5.15, 7.48, 14.26, 61.33, 179.03, 381.3, 703.65,
1239.45, 1982.04, 3109.05)), class = "data.frame", row.names = c(NA,
-13L), .Names = c("Country", "Year", "TotalSales"))


Code:



EV.ss <- nls(TotalSales ~ SSlogis(Year, phi1, phi2, phi3), data = EV_temp)


If anyone could point me in the correct direction in solving this it would be greatly appreciated.










share|improve this question




















  • 1





    Just a guess, but looks like this is because Year is a factor.

    – IceCreamToucan
    Nov 28 '18 at 21:32











  • Thanks yes didn't think of checking that. :) code to fix it: EV_temp$Year<-as.numeric(as.character(EV_temp$Year))

    – user2946746
    Nov 28 '18 at 21:48








  • 1





    Just change "2017"), class = "factor"), into "2017"), class="numeric"),

    – Henry
    Nov 28 '18 at 21:49
















0















I'm trying to fit world sales data for BEV and PHEV to a logistic growth function.



For an example, I'm using R-code for Logistic Growth Model of Australian Population in R (by Elise Gould)



But with this method I'm getting the error:




Error in qr.default(.swts * gr) :
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In Ops.factor(xmid, input) : ‘-’ not meaningful for factors




My data is:



EV_temp<-structure(list(Country = structure(c(21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L), .Label = c("Australia",
"Brazil", "Canada", "Chile", "China", "Finland", "France", "Germany",
"India", "Japan", "Korea", "Mexico", "Netherlands", "New Zealand",
"Norway", "Others", "Portugal", "South Africa", "Sweden", "Thailand",
"Total", "United Kingdom", "United States"), class = "factor"),
Year = structure(1:13, .Label = c("2005", "2006", "2007",
"2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015",
"2016", "2017"), class = "factor"), TotalSales = c(1.89,
2.23, 2.69, 5.15, 7.48, 14.26, 61.33, 179.03, 381.3, 703.65,
1239.45, 1982.04, 3109.05)), class = "data.frame", row.names = c(NA,
-13L), .Names = c("Country", "Year", "TotalSales"))


Code:



EV.ss <- nls(TotalSales ~ SSlogis(Year, phi1, phi2, phi3), data = EV_temp)


If anyone could point me in the correct direction in solving this it would be greatly appreciated.










share|improve this question




















  • 1





    Just a guess, but looks like this is because Year is a factor.

    – IceCreamToucan
    Nov 28 '18 at 21:32











  • Thanks yes didn't think of checking that. :) code to fix it: EV_temp$Year<-as.numeric(as.character(EV_temp$Year))

    – user2946746
    Nov 28 '18 at 21:48








  • 1





    Just change "2017"), class = "factor"), into "2017"), class="numeric"),

    – Henry
    Nov 28 '18 at 21:49














0












0








0








I'm trying to fit world sales data for BEV and PHEV to a logistic growth function.



For an example, I'm using R-code for Logistic Growth Model of Australian Population in R (by Elise Gould)



But with this method I'm getting the error:




Error in qr.default(.swts * gr) :
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In Ops.factor(xmid, input) : ‘-’ not meaningful for factors




My data is:



EV_temp<-structure(list(Country = structure(c(21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L), .Label = c("Australia",
"Brazil", "Canada", "Chile", "China", "Finland", "France", "Germany",
"India", "Japan", "Korea", "Mexico", "Netherlands", "New Zealand",
"Norway", "Others", "Portugal", "South Africa", "Sweden", "Thailand",
"Total", "United Kingdom", "United States"), class = "factor"),
Year = structure(1:13, .Label = c("2005", "2006", "2007",
"2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015",
"2016", "2017"), class = "factor"), TotalSales = c(1.89,
2.23, 2.69, 5.15, 7.48, 14.26, 61.33, 179.03, 381.3, 703.65,
1239.45, 1982.04, 3109.05)), class = "data.frame", row.names = c(NA,
-13L), .Names = c("Country", "Year", "TotalSales"))


Code:



EV.ss <- nls(TotalSales ~ SSlogis(Year, phi1, phi2, phi3), data = EV_temp)


If anyone could point me in the correct direction in solving this it would be greatly appreciated.










share|improve this question
















I'm trying to fit world sales data for BEV and PHEV to a logistic growth function.



For an example, I'm using R-code for Logistic Growth Model of Australian Population in R (by Elise Gould)



But with this method I'm getting the error:




Error in qr.default(.swts * gr) :
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In Ops.factor(xmid, input) : ‘-’ not meaningful for factors




My data is:



EV_temp<-structure(list(Country = structure(c(21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L), .Label = c("Australia",
"Brazil", "Canada", "Chile", "China", "Finland", "France", "Germany",
"India", "Japan", "Korea", "Mexico", "Netherlands", "New Zealand",
"Norway", "Others", "Portugal", "South Africa", "Sweden", "Thailand",
"Total", "United Kingdom", "United States"), class = "factor"),
Year = structure(1:13, .Label = c("2005", "2006", "2007",
"2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015",
"2016", "2017"), class = "factor"), TotalSales = c(1.89,
2.23, 2.69, 5.15, 7.48, 14.26, 61.33, 179.03, 381.3, 703.65,
1239.45, 1982.04, 3109.05)), class = "data.frame", row.names = c(NA,
-13L), .Names = c("Country", "Year", "TotalSales"))


Code:



EV.ss <- nls(TotalSales ~ SSlogis(Year, phi1, phi2, phi3), data = EV_temp)


If anyone could point me in the correct direction in solving this it would be greatly appreciated.







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 21:28









eipi10

60.2k16109165




60.2k16109165










asked Nov 28 '18 at 21:26









user2946746user2946746

5531725




5531725








  • 1





    Just a guess, but looks like this is because Year is a factor.

    – IceCreamToucan
    Nov 28 '18 at 21:32











  • Thanks yes didn't think of checking that. :) code to fix it: EV_temp$Year<-as.numeric(as.character(EV_temp$Year))

    – user2946746
    Nov 28 '18 at 21:48








  • 1





    Just change "2017"), class = "factor"), into "2017"), class="numeric"),

    – Henry
    Nov 28 '18 at 21:49














  • 1





    Just a guess, but looks like this is because Year is a factor.

    – IceCreamToucan
    Nov 28 '18 at 21:32











  • Thanks yes didn't think of checking that. :) code to fix it: EV_temp$Year<-as.numeric(as.character(EV_temp$Year))

    – user2946746
    Nov 28 '18 at 21:48








  • 1





    Just change "2017"), class = "factor"), into "2017"), class="numeric"),

    – Henry
    Nov 28 '18 at 21:49








1




1





Just a guess, but looks like this is because Year is a factor.

– IceCreamToucan
Nov 28 '18 at 21:32





Just a guess, but looks like this is because Year is a factor.

– IceCreamToucan
Nov 28 '18 at 21:32













Thanks yes didn't think of checking that. :) code to fix it: EV_temp$Year<-as.numeric(as.character(EV_temp$Year))

– user2946746
Nov 28 '18 at 21:48







Thanks yes didn't think of checking that. :) code to fix it: EV_temp$Year<-as.numeric(as.character(EV_temp$Year))

– user2946746
Nov 28 '18 at 21:48






1




1





Just change "2017"), class = "factor"), into "2017"), class="numeric"),

– Henry
Nov 28 '18 at 21:49





Just change "2017"), class = "factor"), into "2017"), class="numeric"),

– Henry
Nov 28 '18 at 21:49












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528364%2ffitting-data-to-logistic-function-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528364%2ffitting-data-to-logistic-function-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)